Jump to content
  • Advertisement

Archived

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

Ilthigore

Java INKEY$

This topic is 5792 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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
Advertisement
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

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!