Java Reference
In-Depth Information
The AppOptions frame will be displayed with the Exit button correctly positioned.
7.
Click the Exit button to end the application.
8.
In the AppOptions source code, add the ItemListener to each of the checkboxes.
9.
In AppOptions, add the nested ifs to check each checkbox's state.
10.
Add the source code such that if empAppCB is checked the EnterEmpInfo frame is
displayed. (Define the EnterEmpInfo variable name as eei .)
11.
Add the source code such that if either of the other checkboxes is selected, the message
“Sorry that application is not available” is displayed in the console.
12.
Save the AppOptions source code and run TNT as a Java application.
The “Application Menu” frame should be displayed.
13.
Click the Sorting Application checkbox.
The “Sorry that application not available” message should be displayed in the console.
14.
Click the Employee Application checkbox.
The “EnterEmpInfo” frame should be displayed.
15.
On the EnterEmpInfo frame, click the Exit button.
Notice that both the AppOptions and EnterEmpInfo frame disappear. This is because the Exit button uses the
System.exit() statement, which shuts down the entire JVM.
16.
Run TNT as a Java application, click the Employee Application checkbox, and, on the
EnterEmpInfo frame, click the window close button in the upper right of the frame.
Notice that the AppOptions frame is still displayed. This is because EnterEmpInfo frame's windowClosing
method (which it inherited from UsefulFrame) uses the dispose method, not System.exit(). The dispose method only
deletes the current object (the EnterEmpInfo frame), whereas System.exit() ends the JVM, thereby deleting all objects.
Tutorial: Swing
Earlier we mentioned that there are other GUI component sets available. Swing is one of them and now is a good time
to demonstrate how Swing and AWT are different yet similar. We will duplicate the frame we just created using
Swing components.
1.
In c6, create a new visual class called AppOptionsSwing.
2.
On the New Java Visual Class frame, in the Style pane, specify the superclass by expanding
Swing and selecting Frame.
3.
Also, on the New Java Visual Class frame, implement an AWT action listener, create a main
method stub, and have stubs for the inherited abstract methods.
4.
In the Visual Editor, click on the JFrame title and display the properties view.
Notice that JFrame properties are almost exactly the same as a Frame. However, some of the default values are
different, for instance, the background color.
5.
Display the JFrame source code.
 
Search WWH ::




Custom Search