Package java.awt Previous
Previous
Java API
Java API
Index
Index
Next
Next

Class Checkbox

Constructors , Methods , Footnotes

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".


Constructors


Checkbox

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.


Checkbox

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.

ParameterDescription
label a string label for the check box, or null for no label.


Checkbox

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.

ParameterDescription
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"


Methods


addNotify

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 .


getCheckboxGroup

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 .


getLabel

public String getLabel() 

Return Value:

Returns the label of this check box, or null if this check box has no label.

See Also: setLabel .


getState

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 .


paramString

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 .


setCheckboxGroup

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.

ParameterDescription
g the new check box group, or null to remove the check box from any check box group

See Also: getCheckboxGroup .


setLabel

public void setLabel(String  label) 

Sets this check box's label to be the string argument.

ParameterDescription
label the new label, or null for no label

See Also: getLabel .


setState

public void setState(boolean  state) 

Sets this check box to the specifed boolean state: true indicates "on"; false indicates "off".

ParameterDescription
state the boolean state of the check box.

See Also: getState .


Footnotes

(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.

Top© 1996 Sun Microsystems, Inc. All rights reserved.