这段代码有什么问题?
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;
}
}
}
这应该在控制台中打印测试,但事实并非如此。我究竟做错了什么?