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 });