Java Reference
In-Depth Information
TABLE 12-10 Some Constructors and Methods of the class JCheckBox (continued)
public JCheckBox(String text, Icon icon)
//Creates a check box with the specified image
//and specified label.
//Example: JCheckBox myJCheckBox =
//
new JCheckBox("Box", anIcon);
//
myJCheckBox points to the unselected check box with
//
the label "Box" and anIcon as the icon.
public JCheckBox(String text, Icon icon, boolean selected)
//Creates a check box with the specified image
//and selection state, and with the specified text.
//Example: JCheckBox myJCheckBox =
//
new JCheckBox("Box", anIcon, true);
//
myJCheckBox points to the selected check box with
//
the label "Box" and anIcon as the icon.
public boolean isSelected()
//This method is inherited from the AbstractButton class
//and is used to retrieve the state of a button.
//Example: if(myJCheckBox.isSelected() == true)
//
The "if" block will be executed, provided that myJCheckBox
//
is checked.
public boolean setSelected( boolean b)
//This method is inherited from the AbstractButton class
//and is used to set the state of a button.
//Example: myJCheckBox.setSelected(true);
//
myJCheckBox gets checked.
Similar to buttons, check boxes also come with their own identifying labels. Consider the
following statements:
JCheckBox italicCB;
//Line 1
italicCB = new JCheckBox("Italic");
//Line 2
The statement in Line 1 declares italicCB to be a reference variable of JCheckBox
type. The statement in Line 2 creates the object italicCB and assigns it the label
Italic . After the statement in Line 2 executes, the check box shown in Figure 12-11
results.
FIGURE 12-11 Check box with label
Search WWH ::




Custom Search