Java Reference
In-Depth Information
In the actionPerformed method, we want to display the EnterEmpInfo frame if the first radio button is clicked.
When the other two buttons are clicked, display text saying that the other applications are not available. To determine
which radio button was clicked we will use the action event's getSource method to retrieve the radio button object
that was clicked and compare it to the three radio buttons. This was also very similar to one of the techniques we used
with the AWT checkboxes.
11.
In the actionPerformed method, add the following code:
if (empAppRB == e.getSource()) {
EnterEmpInfo eei = new EnterEmpInfo();}
else if (shipAppRB == e.getSource())
System. out .println("Sorry the ship app is not available");
else if (sortAppRB == e.getSource())
System. out .println("Sorry the sort app is not available");
12.
Run TNTSwing and click the Employee Application radio button.
Notice that a Swing-based object (AppOptionsSwing) can create an AWT-based object (EnterEmpInfo) and
vice versa. Mixing AWT and Swing components is considered bad design because the application lacks a consistent
“look and feel.” However, the purpose of this exercise was not to demonstrate good design but to show how similar
yet different the two GUI component sets are. Remember, the AWT components are easier to use but the Swing
components have extra functions/features.
Tutorial: Using the New Calculation
Let's use the new calculation:
1.
Change EnterEmpInfo frame as follows:
Set the Title to “Enter Employee Information”
Change the names of empCSZlbl to cityLbl and empCSZTF to cityTF
Change the text of cityLbl to “City”
Change the text of cityTF to “Jacksonville”
2.
Create three new labels:
exmpLbl with the text “Exemptions”
stateLbl with the text “State”
zipLbl with the text “Zip”
3.
Create three new textfields:
exmpTF (accept the default size)
stateTF with the text “FL” (accept the default size)
zipTF with the text “322”
4.
Create two new TNTbuttons called dispBtn and taxBtn as follows:
Same size as the Gross button
Labels that say “Display” and “TaxAmt”
5.
Adjust the position of the components so that the frame looks like Figure 6-19 .
 
Search WWH ::




Custom Search