Archived

This topic is now archived and is closed to further replies.

Ilthigore

Java INKEY$

Recommended Posts

My current games in JAVA all use the mouse and I'm trying to implement key listeners. Unlike mouse and action listeners I cant get them to work for some reason. I was wondering if anybody could submit their key listener code as mine WON'T WORK!
  

public class Example extends JApplet
{
    public int inkey()
    {
         int keyScanCode=0;
         //THE CODE I NEED TO ACCEPT KEYBOARD INPUT

         //AND RETURN THE KEYCODE OF THE KEY PRESSED

         return keyScanCode;
    }

    public void paint(Graphics g)
    {
         .
         .
         .
    }

    //AND THE REST OF THE APPLET


}

//MUST BE IMPLEMENTED LIKE THIS:

public class Inkey()
{
    BLAH; 
    BLAH; 
    BLAH; 
    int scanCode=inkey(); 
    BLAH; 
    BLAH; 
}

//or something similar

  
>>>>>>>>>>>>>>>>>>>>>>>>>>>> Ilthigore- <<<<<<<<<<<<<<<<<<<<<<<<<<<< [edited by - ilthigore on August 12, 2002 11:55:49 AM]

Share this post


Link to post
Share on other sites
You have to implement KeyListener, put this.addKeyListener(this) somewhere in your init, write code for KeyTyped(Keyevent e){},KeyPressed(){},and KeyReleased(){} usually at the bottom of the japplet

Share this post


Link to post
Share on other sites