Advertisement

Java INKEY$

Started by August 12, 2002 10:54 AM
0 comments, last by Ilthigore 22 years, 4 months ago
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]
>>>>>>>>>>>>>>>>>Ilthigore<<<<<<<<<<<<<<<<<
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

This topic is closed to new replies.

Advertisement