![]() |
The Java Developers Almanac 1.4Order this book from Amazon. |
e645. Handling Key PressesYou can get the key that was pressed either as a key character (which is a Unicode character) or as a key code (a special value representing a particular key on the keyboard).component.addKeyListener(new MyKeyListener()); public class MyKeyListener extends KeyAdapter { public void keyPressed(KeyEvent evt) { // Check for key characters. if (evt.getKeyChar() == 'a') { process(evt.getKeyChar()); } // Check for key codes. if (evt.getKeyCode() == KeyEvent.VK_HOME) { process(evt.getKeyCode()); } } }
e644. Handling Action Events e646. Handling Mouse Clicks e647. Handling Mouse Motion e648. Detecting Double and Triple Clicks e649. Handling Focus Changes e650. Firing Item Events © 2002 Addison-Wesley. |