Package java.awt |
![]() Previous |
![]() Java API |
![]() Index |
![]() Next |
public class java.awt.Checkbox extends java.awt.Component { // Constructors public Checkbox(); public Checkbox(String label); public Checkbox(String label, CheckboxGroup group, boolean state); // Methods public void addNotify(); public CheckboxGroup getCheckboxGroup(); public String getLabel(); public boolean getState(); protected String paramString(); public void setCheckboxGroup(CheckboxGroup g); public void setLabel(String label); public void setState(boolean state); }
A check box is a graphical component that has an "on" (true) and "off" (false) state. Clicking on the check box changes its state from "on" to "off" or from "off" to "on".
For example, the code:
setLayout(new GridLayout(3, 1)); add(new Checkbox("one", null, true)); add(new Checkbox("two")); add(new Checkbox("three"));
produces the following three check boxes:
The button labelled one is "on". The other two are "off".
When the check box is clicked,(1) AWT sends an action event to the check box. This event's target is the check box, and its object is a Boolean giving the new state of the check box. An application should override the action method of the check box or of one of its containing windows in order to cause some action to occur.
Optionally, several checkboxes can be grouped together into a CheckboxGroup . At most one button in a group can be in the "on" state at any given time. Pushing a check box to turn it "on" forces any other check box in the group that is "on" to become "off".
public Checkbox()Creates a check box with no label. The check box is set to "off" and is not part of any check box group.
public Checkbox(String label)Creates a check box with the specified label. The check box is set to "off" and is not part of any check box group.
Parameter Description label a string label for the check box, or null for no label.
public Checkbox(String label, CheckboxGroup group, boolean state)Creates a check box with the specified label, in the specified check box group, and set to the specified state.
Parameter Description label a string label for the check box, or null for no label group this check box's check box group, or null for no group state the initial state of the check box: true indicates "on"; false indicates "off"
public void addNotify()This method calls the createCheckbox method of the check box's toolkit in order to create a CheckboxPeer for this button. This peer allows the application to change the look of a check box without changing its functionality.
Most applications do not call this method directly.
Overrides:
addNotify in class Component .
public CheckboxGroup getCheckboxGroup()Determines this check box's group.
Return Value:
Returns thischeck box's group, or null if it is not part of a check box group.
See Also: setCheckboxGroup .
public String getLabel()Return Value:
Returns the label of this check box, or null if this check box has no label.
See Also: setLabel .
public boolean getState()Determines if this check box is "on" or "off."
Return Value:
Returns the state of this check box. The value true indicates "on", false indicates "off".
See Also: setState .
protected String paramString()Returns the parameter string representing the state of this check box. This string is useful for debugging.
Return Value:
Returns the parameter string of this check box.
Overrides:
paramString in class Component .
public void setCheckboxGroup(CheckboxGroup g)Sets the group of this check box to be the specified check box group. If this check box is already in a different check box group, it is first taken out of that group.
Parameter Description g the new check box group, or null to remove the check box from any check box group See Also: getCheckboxGroup .
public void setLabel(String label)Sets this check box's label to be the string argument.
Parameter Description label the new label, or null for no label See Also: getLabel .
public void setState(boolean state)Sets this check box to the specifed boolean state: true indicates "on"; false indicates "off".
Parameter Description state the boolean state of the check box. See Also: getState .
(1)In Java 1.0, the AWT does not send mouse or focus events to a check box. In Java 1.1, the AWT sends the check box all mouse, keyboard, and focus events that occur over it.