Java Reference
In-Depth Information
public static void main(String[] args) {
}
}
So far, part of step A and all of steps B and C (from above) have been coded. Because we coded a little, let's
test a little.
2.
Add the following constructor:
public CBTestApp() {
setVisible( true );
}
3. Add the following statement to the main method:
CBTestApp cbta = new CBTestApp();
4.
Save the source and run CBTestApp as a Java application.
A very boring frame should be displayed. This boring frame, however, proves that everything has been coded
correctly, so let's not ridicule it too much.
5.
Click the Close button to close the frame.
6.
After the existing import statements, add the following statements:
import java.awt.Checkbox;
import java.awt.CheckboxGroup;
This finishes step A.
7.
Add the following statement to create a class variable of type Checkbox called empAppCB
and assign a new Checkbox object with the text “Employee Application” to empAppCB.
private Checkbox empAppCB = new Checkbox("Employee
Application");
This starts step D.
8.
In the constructor, before the frame is set visible, add the following statements.
empAppCB.setBounds(94, 62, 148, 23);
empAppCB.addItemListener( this );
add(empAppCB);
The first statement finishes the checkbox definition (as specified in step D). The second statement adds the
ItemListener to the checkbox (as specified in step E). The third statement adds the checkbox to the frame (as specified
in step H). So far, we have done steps A through E and step H. This is enough code to test that the checkbox appears
on the frame and that the ItemListener has been added correctly.
9.
Add the following statement to the itemStateChanged method:
System.out.println("Checkbox was clicked!");
 
Search WWH ::




Custom Search