Java Reference
In-Depth Information
Can you explain why/how this new statement tests that the ItemListener has been tied to the checkbox?
10.
Save the source and run CBTestApp as a Java application.
11.
On the frame, click the checkbox four times and click the Window Close button.
The text from the println statement should appear four times in the console. In addition, the check mark should
have appeared and/or disappeared each time the checkbox was clicked. Notice also that clicking anywhere on the
checkbox (the label or the tiny text field) changes the state.
Tutorial: Coding a Checkbox Group
We need to add a couple more checkboxes, define a checkbox group (step F), and then add the checkboxes to the
checkbox group (step G).
1.
Define two more checkboxes by placing each of the following statements in its correct
location within CBTestApp:
private Checkbox shipAppCB = new Checkbox(
"Shipment Application");
private Checkbox sortAppCB = new Checkbox(
"Sorting Application");
shipAppCB.setBounds(94, 142, 148, 23);
add(shipAppCB);
shipAppCB.addItemListener( this );
sortAppCB.setBounds(94, 222, 148, 23);
add(sortAppCB);
sortAppCB.addItemListener( this );
setExitButtonLocation();
Let's test that you added the statements in the right places.
2.
Save the source and run CBTestApp as a Java application.
If you added the statements correctly, the frame should appear as in Figure 6-15 .
 
Search WWH ::




Custom Search