Packages  This Package  Prev  Next  Index  

§1.5 Class Checkbox

public  class  java.awt.Checkbox
    extends  java.awt.Component  (II-§1.10)
{
        // Constructors
    public Checkbox();	§1.5.1
    public Checkbox(String  label);	§1.5.2
    public Checkbox(String  label, CheckboxGroup  group,  §1.5.3
                                        boolean  state);

        // Methods
    public void addNotify();	§1.5.4
    public CheckboxGroup getCheckboxGroup();	§1.5.5
    public String getLabel();	§1.5.6
    public boolean getState();	§1.5.7
    protected String paramString();	§1.5.8
    public void setCheckboxGroup(CheckboxGroup  g);	§1.5.9
    public void setLabel(String  label);	§1.5.10
    public void setState(boolean  state);	§1.5.11
}
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 (II-§1.14.11) to the check box. This event's target is the check box, and its object is a Boolean (I-§1.1) giving the new state of the check box. An application should override the action method (II-§1.10.1) 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 (II-§1.6). 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.
Parameters:
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.
Parameters:
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 (II-§1.41.5) of the check box's toolkit (II-§1.10.20) in order to create a CheckboxPeer (II-§3.4) 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 (II-§1.10.2).

getCheckboxGroup

public CheckboxGroup getCheckboxGroup()
Determines this check box's group.
Returns:
thischeck box's group, or null if it is not part of a check box group.
See Also:
setCheckboxGroup (II-§1.5.9).

getLabel

public String getLabel()
Returns:
the label of this check box, or null if this check box has no label.
See Also:
setLabel (II-§1.5.10).

getState

public boolean getState()
Determines if this check box is "on" or "off."
Returns:
the state of this check box. The value true indicates "on", false indicates "off".
See Also:
setState (II-§1.5.11).

paramString

protected String paramString()
Returns the parameter string representing the state of this check box. This string is useful for debugging.
Returns:
the parameter string of this check box.
Overrides:
paramString in class Component (II-§1.10.51).

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.
Parameters:
g - the new check box group, or null to remove the check box from any check box group
See Also:
getCheckboxGroup (II-§1.5.5).

setLabel

public void setLabel(String label)
Sets this check box's label to be the string argument.
Parameters:
label - the new label, or null for no label
See Also:
getLabel (II-§1.5.6).

setState

public void setState(boolean state)
Sets this check box to the specifed boolean state: true indicates "on"; false indicates "off".
Parameters:
state - the boolean state of the check box.
See Also:
getState (II-§1.5.7).

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.

Packages  This Package  Prev  Next  Index
Java API Document (HTML generated by dkramer on April 22, 1996)
Copyright © 1996 Sun Microsystems, Inc. All rights reserved
Please send any comments or corrections to doug.kramer@sun.com