i'm interested in capturing the escape key
whenever i press it i want system.exit(1);
any help on that?
1 reply to this topic
#1
Posted 16 January 2011 - 06:03 AM
|
|
|
#2
Posted 16 January 2011 - 07:05 AM
addKeyListener(new KeyListener() {
public void keyTyped(KeyEvent e) {}
public void keyPressed(KeyEvent e) {
if(e.getKeyCode() == KeyEvent.VK_ESCAPE){
frame.dispose();
}
}
public void keyReleased(KeyEvent e) {}
});
You do the addKeyListener on the object where you want to catch it on. Could be a JFrame, JPanel, JTextField, any gui component
JFrame frame; ... frame.addKeyListener(...);
extra info: How to Write a Key Listener (The Java™ Tutorials > Creating a GUI With JFC/Swing > Writing Event Listeners)
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users


Sign In
Create Account


Back to top









