Java - KeyListner
What is wrong with this code?
addKeyListener(new KeyHandler());
private class KeyHandler extends KeyAdapter {
public void keyPressed(KeyEvent e) {
super.keyPressed(e);
int key = e.getKeyCode();
System.out.println("test");
if(key==KeyEvent.VK_SPACE || key==KeyEvent.VK_ENTER ||
key==KeyEvent.VK_P) {
paused = true;
}
}
}
This should print test in the console but it doesn't. What am I doing wrong?
No comments:
Post a Comment