Jump to content

View more

Image of the Day

Inventory ! Va falloir trouver une autre couleur pour le cadre D: #AzTroScreenshot #screenshotsaturday https://t.co/PvxhGL7cOH
IOTD | Top Screenshots

The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.


Sign up now

Controlling Multiple Classes with KeyListeners

4: Adsense

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.


  • You cannot reply to this topic
No replies to this topic

#1 epicpunnum   Members   

459
Like
0Likes
Like

Posted 29 October 2012 - 06:19 PM

Hello there! I wanted to ask if there was any way to create a class controllable via KeyListener without the class being a Component or Window. I remember achieving something along those lines by creating a custom child class of KeyListener, however I forget on how I applied it in my code. My closest approach was using this code below, but even still it didn't work.
public Menu(){
  Component c = new Component(){};
  c.addKeyListener(new KeyListener(){
   public void keyPressed(KeyEvent e) {}
   public void keyReleased(KeyEvent e) {}
  
   public void keyTyped(KeyEvent e) {
    int theCode = e.getKeyCode();
    if (theCode==KeyEvent.VK_DOWN)
	 mIndex++;
   }
  });
}
I can't find the original code anywhere in my archive of work, so I was wondering if anyone could point me in the right direction.
-Cheers




Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.