键盘监听事件
public class TestKeyListener {
public static void main(String[] args) {
new KeyFrame();
}
}
class KeyFrame extends Frame{
public KeyFrame() {
setBounds(100,100,400,400);
setBackground(new Color(208, 39, 39));
setVisible(true);
addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
this.addKeyListener(new KeyAdapter() {
@Override
public void keyPressed(KeyEvent e) {
int keycode=e.getKeyCode();
if(keycode==KeyEvent.VK_UP){
System.out.println(keycode);
System.out.println("键盘事件上键");
}
}
});
}
}