32.9. Review Questions

 
[Page 1001]

Chapter Summary

  • Menus make selection easier and are widely used in window applications. Java provides five classes that implement menus : JMenuBar , JMenu , JMenuItem, JCheckBoxMenuItem , and JRadioButtonMenuItem . These classes are subclasses of AbstractButton . They are very similar to buttons .

  • JMenuBar is a top-level menu component used to hold menus. A menu consists of menu items that the user can select (or toggle on or off). A menu item can be an instance of JMenuItem , JCheckBoxMenuItem , or JRadioButtonMenuItem . Menu items can be associated with icons, keyboard mnemonics , and keyboard accelerators. Menu items can be separated using separators.

  • A popup menu, also known as a context menu , is like a regular menu, but does not have a menu bar and can float anywhere on the screen. Creating a popup menu is similar to creating a regular menu. First, you create an instance of JPopupMenu , then you can add JMenuItem , JCheckBoxMenuItem , JRadioButtonMenuItem , and separators to the popup menu.

  • A popup menu usually contains the commands for an object. Customarily, you display a popup menu by pointing to the object and clicking a certain mouse button, the so-called popup trigger . Popup triggers are system-dependent. In Windows, the popup menu is displayed when the right mouse button is released. In Motif, the popup menu is displayed when the third mouse button is pressed and held down.

  • Swing provides the JToolBar class as the container to hold tool bar components . JToolBar uses BoxLayout to manage components. The components usually appear as icons. Since icons are not components, they cannot be placed into a tool bar directly. Instead you place buttons into the tool bar and set the icons on the buttons. An instance of JToolBar is like a regular container. Often it is placed in the north, west, or east of a container of BorderLayout .

  • Swing provides the Action interface, which can be used to create action objects for processing actions. Using Action objects, common action processing for menu items and tool bar buttons can be centralized and separated from the other application code.

  • The JOptionPane class contains the static methods for creating message dialogs, confirmation dialogs, input dialogs, and option dialogs. You can also create custom dialogs by extending the JDialog class.

  • Swing provides a convenient and versatile color dialog named javax.swing.JColorChooser . Like JOptionPane , JColorChooser is a lightweight component inherited from JComponent . It can be added to any container.

  • Swing provides the javax.swing.JFileChooser class that displays a dialog box from which the user can navigate through the file system and select files for loading or saving.

  • You can create internal frames using the JInternalFrame class. This user interface is commonly known as a multiple document interface or MDI . The JInternalFrame class is almost the same as the external JFrame class. The components are added to the internal frame in the same way as they are added to the external frame. An internal frame can have menus, a title, a Close icon, a Minimize icon, and a Maximize icon just like an external frame.

 


Introduction to Java Programming-Comprehensive Version
Introduction to Java Programming-Comprehensive Version (6th Edition)
ISBN: B000ONFLUM
EAN: N/A
Year: 2004
Pages: 503

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net