Jump to content

  • Log In with Google      Sign In   
  • Create Account


Controlling Multiple Classes with KeyListeners


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   -  Reputation: 454

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

Sponsor:



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.



PARTNERS