img
FIGURE 24-8
Sample output from the MenuDemo applet
Sample output from the MenuDemo applet is shown in Figure 24-8.
There is one other menu-related class that you might find interesting: PopupMenu.
It works just like Menu, but produces a menu that can be displayed at a specific location.
PopupMenu provides a flexible, useful alternative for some types of menuing situations.
Dialog Boxes
Often, you will want to use a dialog box to hold a set of related controls. Dialog boxes are
primarily used to obtain user input and are often child windows of a top-level window.
Dialog boxes don't have menu bars, but in other respects, they function like frame windows.
(You can add controls to them, for example, in the same way that you add controls to a
frame window.) Dialog boxes may be modal or modeless. When a modal dialog box is active,
all input is directed to it until it is closed. This means that you cannot access other parts of
your program until you have closed the dialog box. When a modeless dialog box is active,
input focus can be directed to another window in your program. Thus, other parts of your
program remain active and accessible. Dialog boxes are of type Dialog. Two commonly
used constructors are shown here:
Dialog(Frame parentWindow, boolean mode)
Dialog(Frame parentWindow, String title, boolean mode)
Here, parentWindow is the owner of the dialog box. If mode is true, the dialog box is modal.
Otherwise, it is modeless. The title of the dialog box can be passed in title. Generally, you
will subclass Dialog, adding the functionality required by your application.
Following is a modified version of the preceding menu program that displays a modeless
dialog box when the New option is chosen. Notice that when the dialog box is closed,
dispose( ) is called. This method is defined by Window, and it frees all system resources
associated with the dialog box window.
// Demonstrate Dialog box.
import java.awt.*;
import java.awt.event.*;
Search WWH :
Custom Search
Previous Page
Java SE 6 Topic Index
Next Page
Java SE 6 Bookmarks
Home