I have a program which produces a JFrame and then a JPanel on top of it. For the program, I have tried implementing the KeyListener and then adding the methods (for both components), but the program does not pick any of my key strokes up. What am I doing wrong?
EDIT
This is my code. It is a part of the class which creates the JFrame. It still does not pick up the press of the ESC key.
@Override
public void keyTyped(KeyEvent e) {
}
@Override
public void keyPressed(KeyEvent e) {
int keyCode = e.getKeyCode();
if(keyCode == KeyEvent.VK_ESCAPE){
System.out.println("Hi");
}else{
System.out.println("Hello");
}
}
@Override
public void keyReleased(KeyEvent e) {
}