Menu Shortcuts Menu Shortcut button The Ability To Specify Menu Shortcuts IS One of the Features in JDK 1.1 - WHERE MENU Choices Instead of with the mouse. The implementation of menu shortcuts is available in JDK1.1. Quick Key --- That is to replace the mouse selection menu item using the keyboard.
For example: An example: // Import the required package import java.awt. *; Import java.awt.event. *; // menu class, implement the actionListener interface public class menu imports anctionsListener {public void actionPerformed (ActionEvent E) { String lab = ((menuItem) E.GETSource ()). GetLabel (); system.out.println ("label =" lab); if (Lab.Equals ("exit")) {system.exit (0) }}
Public static void main (String args []) {frame f = new menu ("file"); menu acl = new menu (); menuitem mi1 = new menuItem ("open" ); Mi1.AddActionListener (ACL); M.Add (MI1); Menuitem Mi2 = New MenuItem ("save"); Mi2.AddActionListener (ACL); M.Add (MI2); // Create shortcuts, here will Depending on the platform, use shortcuts, under Windows, will be C E MENUSHORTCUT MS3 = New Menushortcut (KeyEvent.vk_e); MenuItem MI3 = New MenuItem ("EXIT", MS3); Mi3.AddActionListener (ACL); M .add (mi3); menubar MB = new menubar (); Mb.Add (m); F.setmenubar (MB); F.setSize (200, 200); f.setVisible (TRUE);}
}
The Example Sets Up A Frame, Which Is A Top-Level Application Window. The Frame Contains A Menu Bar, And The Menu Bar Contains A Single Pull-Down Menu Named "File." The menu Offers Choices for Open, Save, And Exit This example built a Frame as a top window, the window has a menu bar, and the File menu is only available in the menu bar. Open, save, exit three, exit items Bind a shortcut key E.
How the shortcut gets invoked varies, depending on the platform in question. For example, with Windows you use Ctrl-E so that when a user types Ctrl-E within the window containing the menu bar, the Exit command is invoked. Shortcuts through What ways are depends on the platform, for example, under Windows, CTRL-E, when you press CTRL-E, the exit command will execute.
One last thing: this example does not actually (in fact, actually) have a command structure (building, construction) set up for it, but instead invokes actionPerformed to demonstrate (prove) that the command processing structure is in place last. Winning: This example does not actually build a command processing structure, but only calls an actionPerformed certificate that the command processing structure has been executed correctly.