The Example has a single JMenu (Fruits) in the menu bar. The Fruits menu contains 4 menu items in which the second menu will invoke a sub-menu. Three items are in the sub-menu. The JMenu fruits is having an underline below the letter F. The same way all its four menu items have an underline in it. For example, to invoke Apple, the user will hit Alt+F+A. The Menu Item Grapes and the menu item Type II contains greyed letters which denote Ctrl+G and Shift+B. For example, a user can invoke the menu item Type II using the keystrokes CTRL & B. Underline denotes Mnemonic and Greyed out letters denotes menu accelerators. Now we will proceed with creating this example.
Tag Archive for ‘KeyEvent’
Java AWT tracks Keyboard Event through KeyListener. The KeyListener will get the KeyEvent which discloses data of user interaction with the keyboard. For example, it holds what key is typed by the user. The KeyEvent is raised when the user pressed a keyboard key and it also raised when he/she released it. The Event also tells what key is typed by the user. When these actions take place, AWT reports the KeyEvent to KeyListener. The KeyListener receives the KeyEvent on exposed function which tells what action is done by the user. The handler functions exposed by the KeyListener are below:
(1) keyPressed(KeyEvent e)
(2) keyReleased(KeyEvent e)
(3) keyTyped(KeyEvent e)
Below picture shows the relation between KeyEvent and KeyListener: