键盘监听事件

 

 

public class demo01 {
    public static void main(String[] args) {
        new KeyFrame("hahhahhs");
    }
}
class KeyFrame extends Frame{
    public KeyFrame(String title){
        super(title);
        setBounds(200,200,300,300);
        setVisible(true);
       addKeyListener(new KeyAdapter() {
           @Override
           public void keyPressed(KeyEvent e) {
               int keyCOde=e.getKeyCode();
               if (keyCOde == KeyEvent.VK_UP){
                   System.out.println("你按下了上键");
               }
           }
       });
    }
}

 

posted on 2022-08-05 17:55  大风吹过12138  阅读(28)  评论(0)    收藏  举报

导航