Results 1 to 3 of 3
Thread: Help! How do I....
- 09-18-2008, 10:36 PM #1Member
- Join Date
- Sep 2008
- Rep Power
- 09-18-2008, 11:34 PM #2
add keylistener to your JComponent and you should know the ID of KeyEvent ,if it equals to KeyEvent.VK_ESCAPE,then call the function System.exit(0);
If you're creating a Swing application (important information that you really should have in your initial post, you know), I'd recommend using key binding rather than keylisteners. The former works even if the JComponent to which it is bound doesn't have the focus. Also, it is a higher level abstraction than keylisteners and you should try to avoid lower level abstractions when they can be avoided. See the Sun key binding tutorial for more details on this.