Menu shortcuts
Shortcut menu
The ability to specify menu shortcuts is one of the features in JDK 1.1 -- where menu choices can be selected via the keyboard instead of with the mouse.
In jdk1.1, the menu shortcut key is provided. The shortcut key is to use the keyboard instead of the mouse to select the menu item.
For example:
Example:
// Import the required package
Import java. AWT .*;
Import java. AWT. event .*;
// Menu class, implementing the actionlistener Interface
Public Class Menu implements actionlistener {
Public void actionreceivmed (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 frame ("testing ");
Menu M = 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 a shortcut. The Shortcut Keys depend on the platform. In Windows, the shortcut keys are 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, with exit having a keyboard shortcut cut set up for it that specifies the virtual key code" E."
In this example, a frame is built as the top-level window. The window has a menu bar with only one menu item, and the File menu provides three items: open, save, and exit, the exit entry is bound with 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.
The shortcut key depends on the platform. For example, in windows, the key corresponds to Ctrl-E. When you press Ctrl-e, the exit command is executed.
one last thing: this example doesn't actually (in fact, actually) have a command structure (build, construct) set up for it, but instead invokes action=med to demonstrate (Proof) that the command processing structure is in place.
last thing: this example does not actually build a command processing structure, but it only calls actionmongomed to prove that the command processing structure has been correctly executed.