Java Reference
In-Depth Information
The mnemonic brings the focus on a menu or menu item but it doesn't select
it. Pressing the Return or Enter key on the keyboard then selects that menu item.
To create a shortcut keystroke to fire a menu item, use an accelerator key ,which
causes the item to be selected immediately. The following line will cause the
Ctrl-q pair to select the Exit item:
menuExit.setAccelerator (KeyStroke.getKeyStroke (
KeyEvent.VK - Q, ActionEvent.CTRL - MASK));
The FrameMenuApp class implements the ActionListener class, and the
frame object is added to both menu items. A separator line is inserted into the
menu with the following:
menu.addSeparator ();
Note that a nice feature of the Swing JApplet is that it allows a menu bar on
the panel on the browser page. Previously, the heavyweight menu bar component
could not be put onto the applet within the browser. The lightweight Swing menus
are simply drawn on the panel like any other Swing component.
7.7 User interface with histogram display
In this section we add interactive graphics components to the histogram dis-
play discussed in Chapter 6 so that the user can control with the program.
Figure 7.15 shows the histogram user interface display obtained from the
program UIDrawHistApplet listed below. We use the same Histogram ,
Figure 7.15 This graphical user interface combines a histogram with a set of
control components. The user enters into a JTextField the number of Gaussian
random numbers to generate and the buttons initiate the generation, display
statistics about the distribution, clear the histogram, and end the program.
Search WWH ::




Custom Search