I working on a java application. I want to implement a KeyListener, on the arrows key. I have a class that extends JFrame and implements ActionListener
public class MyClass extends JFrame implements ActionListener{
}
How can I add a keyboard listener on the arrow keys in this frame?
I tried to do the following in the constructor, but it did not work:
this.addKeyListener(new KeyListener() {
@Override
public void keyPressed(KeyEvent e) {
if(e.getKeyCode() == KeyEvent.VK_UP)
{
//DO Some things
}
}
@Override
public void keyTyped(KeyEvent e) {
}
@Override
public void keyReleased(KeyEvent e) {
}
});
Any help is greatly appreciated. Thanks