Computer Science Canada

Key Listener Event

Author:  void [ Tue May 10, 2005 12:04 pm ]
Post subject:  Key Listener Event

i was wondering if you guys know how to write a proper key listener, for a simple frogerr game..iwant user key input..but everything im trying doesnt work..im not on my comptuer rite now..but when i get home ill post my code for you guys..any help would be appreciated Very Happy

Author:  wtd [ Tue May 10, 2005 4:42 pm ]
Post subject: 

http://java.sun.com/j2se/1.5.0/docs/api/java/awt/event/KeyEvent.html
http://java.sun.com/j2se/1.5.0/docs/api/java/awt/event/KeyListener.html

Something like:

Java:
public class JApplet implements KeyListener
{
   public void keyPressed(KeyEvent e)
   {
      switch (e.getKeyCode())
      {
         case KeyEvent.VK_UP:
            // move up
            break;
         case KeyEvent.VK_DOWN:
            // move down
            break;
         case KeyEvent.VK_LEFT:
            // move left
            break;
         case KeyEvent.VK_RIGHT:
            // move right
            break;
         default:
            break;
      }
   }

   public void keyReleased(KeyEvent e)
   {
      // nada
   }

   public void keyTyped(KeyEvent e)
   {
      // nada
   }
}


: