Java Reference
In-Depth Information
2. The message (a String ). In the example, it is "Are you a vegetari-
an?" .
3. The title (a String ). In the example, it is: "question message" .
4. Defines what buttons appear in the window if the sixth parameter is null .
We always use 0 for the corresponding argument.
5. The style of the window, which tells what picture to put in the window.
This is one of the following JOptionPane constants:
6. An array of button titles. In Fig. 17.20, the array is {"yes", "nein",
"maybe"} . Actually, this parameter is any array of objects. Array ele-
ments that are strings are turned into buttons; array elements that are not
strings are simply placed in the window in some fashion.
7. The component in the array (see parameter 6) that should be highlighted
when the window appears. In this example, "nein" . Striking the enter
key is equivalent to clicking this button.
The result of a call is the index in the button array of the button that was
clicked or, if the close button was clicked, value JOptionPane.CLOSED_OPTION .
Class JDialog
An instance of class JDialog is a bare window that can be used to create a dia-
log with the user. As with a JFrame , you can add whatever components you want
to its content pane and listen to them. And, as with all the methods discussed in
Sec. 17.5.1 on JOptionPanes , you can define the parent frame and title.
You also have the ability to make the window non-modal, which means that
other processing can go on while the dialog window is visible on the monitor,
which you cannot do using the JOptionPane methods.
To find out more about JDialog , look at the Java API specs for it. Look also
at the tutorial for it that is referenced in the web page for lesson 17 on the
ProgramLive CD.
Key concepts
GUI . A GUI is a graphical user-interface. In Java, GUIs are developed using
classes in the older package java.awt and the newer package javax.swing .
Top-level windows . The classes whose instances can be independent windows
are: Window , JWindow , Frame , JFrame , and JDialog (or their subclasses).
Search WWH ::

Custom Search