java.awt

Class Checkbox

public class Checkbox extends Component implements ItemSelectable, Accessible, Serializable

This class implements a component which has an on/off state. Two or more Checkboxes can be grouped by a CheckboxGroup.
Nested Class Summary
protected classCheckbox.AccessibleAWTCheckbox
This class provides accessibility support for the checkbox.
Constructor Summary
Checkbox()
Initializes a new instance of Checkbox with no label, an initial state of off, and that is not part of any checkbox group.
Checkbox(String label)
Initializes a new instance of Checkbox with the specified label, an initial state of off, and that is not part of any checkbox group.
Checkbox(String label, boolean state)
Initializes a new instance of Checkbox with the specified label and initial state, and that is not part of any checkbox group.
Checkbox(String label, CheckboxGroup group, boolean state)
Initializes a new instance of Checkbox with the specified label, initial state, and checkbox group.
Checkbox(String label, boolean state, CheckboxGroup group)
Initializes a new instance of Checkbox with the specified label, initial state, and checkbox group.
Method Summary
voidaddItemListener(ItemListener listener)
Adds a new listeners to the list of registered listeners for this object.
voidaddNotify()
Creates this object's native peer.
AccessibleContextgetAccessibleContext()
Gets the AccessibleContext associated with this Checkbox.
CheckboxGroupgetCheckboxGroup()
Returns the checkbox group this object is a member of, if any.
ItemListener[]getItemListeners()
StringgetLabel()
Returns the label for this checkbox.
Object[]getSelectedObjects()
Returns an array of length one containing the checkbox label if this checkbox is selected.
booleangetState()
Returns the state of this checkbox.
protected StringparamString()
Returns a debugging string for this object.
protected voidprocessEvent(AWTEvent event)
Processes this event by calling processItemEvent() if it is any instance of ItemEvent.
protected voidprocessItemEvent(ItemEvent event)
Processes this event by dispatching it to any registered listeners.
voidremoveItemListener(ItemListener listener)
Removes a listener from the list of registered listeners for this object.
voidsetCheckboxGroup(CheckboxGroup group)
Sets this object's checkbox group to the specified group.
voidsetLabel(String label)
Sets the label for this checkbox to the specified value.
voidsetState(boolean state)
Sets the state of this checkbox to the specified value.

Constructor Detail

Checkbox

public Checkbox()
Initializes a new instance of Checkbox with no label, an initial state of off, and that is not part of any checkbox group.

Checkbox

public Checkbox(String label)
Initializes a new instance of Checkbox with the specified label, an initial state of off, and that is not part of any checkbox group.

Parameters: label The label for this checkbox.

Checkbox

public Checkbox(String label, boolean state)
Initializes a new instance of Checkbox with the specified label and initial state, and that is not part of any checkbox group.

Parameters: label The label for this checkbox. state The initial state of the checkbox, true for on, false for off.

Checkbox

public Checkbox(String label, CheckboxGroup group, boolean state)
Initializes a new instance of Checkbox with the specified label, initial state, and checkbox group.

Parameters: label The label for this checkbox. group The checkbox group for this box, or null if there is no checkbox group. state The initial state of the checkbox, true for on, false for off.

Checkbox

public Checkbox(String label, boolean state, CheckboxGroup group)
Initializes a new instance of Checkbox with the specified label, initial state, and checkbox group.

Parameters: label The label for this checkbox. state The initial state of the checkbox, true for on, false for off. group The checkbox group for this box, or null if there is no checkbox group.

Method Detail

addItemListener

public void addItemListener(ItemListener listener)
Adds a new listeners to the list of registered listeners for this object.

Parameters: listener The new listener to add.

addNotify

public void addNotify()
Creates this object's native peer.

getAccessibleContext

public AccessibleContext getAccessibleContext()
Gets the AccessibleContext associated with this Checkbox. The context is created, if necessary.

Returns: the associated context

getCheckboxGroup

public CheckboxGroup getCheckboxGroup()
Returns the checkbox group this object is a member of, if any.

Returns: This object's checkbox group, of null if it is not a member of any group.

getItemListeners

public ItemListener[] getItemListeners()

getLabel

public String getLabel()
Returns the label for this checkbox.

Returns: The label for this checkbox.

getSelectedObjects

public Object[] getSelectedObjects()
Returns an array of length one containing the checkbox label if this checkbox is selected. Otherwise null is returned.

Returns: The selection state of this checkbox.

getState

public boolean getState()
Returns the state of this checkbox.

Returns: The state of this checkbox, which will be true for on and false for off.

paramString

protected String paramString()
Returns a debugging string for this object.

processEvent

protected void processEvent(AWTEvent event)
Processes this event by calling processItemEvent() if it is any instance of ItemEvent. Otherwise it is passed to the superclass for processing.

Parameters: event The event to process.

processItemEvent

protected void processItemEvent(ItemEvent event)
Processes this event by dispatching it to any registered listeners.

Parameters: event The ItemEvent to process.

removeItemListener

public void removeItemListener(ItemListener listener)
Removes a listener from the list of registered listeners for this object.

Parameters: listener The listener to remove.

setCheckboxGroup

public void setCheckboxGroup(CheckboxGroup group)
Sets this object's checkbox group to the specified group.

Parameters: group The new checkbox group, or null to make this object part of no checkbox group.

setLabel

public void setLabel(String label)
Sets the label for this checkbox to the specified value.

Parameters: label The new checkbox label.

setState

public void setState(boolean state)
Sets the state of this checkbox to the specified value.

Parameters: state The new state of the checkbox, which will be true for on or false for off.