Swing 添加Esc快捷键退出程序

 1 JFrame demo = new JFrame();
 2 demo.addKeyListener(
 3     new KeyListener(){
 4             public void keyReleased(KeyEvent e) {
 5                  if (e.getKeyCode() == KeyEvent.VK_ESCAPE ) {  
 6                                 UIHelper.closeWindow(demo);
 7  8                   }                    
 9             }
10             public void keyTyped(KeyEvent e) {
11             }
12             public void keyPressed(KeyEvent e) {
13             }
14 }); 

 

posted @ 2016-08-12 13:58  伊小白  阅读(1221)  评论(0编辑  收藏  举报