Java Reference
In-Depth Information
LISTING 10.1
Continued
59: } catch (Exception e) {
60: System.err.println(“Couldn't use the system “
61: + “look and feel: “ + e);
62: }
63: }
64:
65: public static void main(String[] arguments) {
66: FeedInfo frame = new FeedInfo();
67: }
68: }
After you fill in the fields in each dialog box, you will see the application's main win-
dow, which is displayed in Figure 10.10 with the Windows look and feel. Three text
fields have values supplied by dialog boxes.
FIGURE 10.10
The main window
of the FeedInfo
application.
Much of this application is boilerplate code that can be used with any Swing application.
The following lines relate to the dialog boxes:
In lines 22-24, an input dialog box asks the user to enter a site name. This name is
used in the constructor for a JTextField object, placing it in the text field.
n
In lines 27-29, a similar input dialog box asks for a site address, which is used in
the constructor for another JTextField object.
n
In line 32, an array of String objects called choices is created, and three elements
are given values.
n
In lines 33-40, an option dialog box asks for the site type. The choices array is
the seventh argument, which sets up three buttons on the dialog box labeled with
the strings in the array: “Personal” , “Commercial” , and “Unknown” . The last argu-
ment, choices[0] , designates the first array element as the default selection in the
dialog box.
n
In line 41, the response to the option dialog box, an integer identifying the array
element that was selected, is stored in a JTextField component called type .
n
 
Search WWH ::




Custom Search