Sign in to follow this  

Controlling Multiple Classes with KeyListeners

This topic is 1905 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

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)
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.

Share this post

Link to post
Share on other sites
Sign in to follow this