java::awt::Checkbox Class Reference

Inheritance diagram for java::awt::Checkbox:

Inheritance graph
java::awt::Componentjava::lang::Objectjava::lang::Interfacejava::lang::Syncjava::awt::event::ComponentSourcejava::awt::event::FocusSourcejava::awt::event::HierarchySourcejava::awt::event::KeySourcejava::awt::event::MouseSourcejava::awt::event::PaintSourcejava::util::PropertyChangeSourcejava::awt::ItemCheckablejava::awt::event::ItemSourcejava::lang::Lockjava::lang::ScopeAdapterjava::awt::image::ImageObserverjava::util::EventSourcejava::awt::ItemSelectable
[legend]
Collaboration diagram for java::awt::Checkbox:

Collaboration graph
java::awt::Componentjava::lang::Objectjava::lang::Interfacejava::lang::ObjectRefjava::lang::Syncjava::awt::event::ComponentSourcejava::awt::event::FocusSourcejava::awt::event::HierarchySourcejava::awt::event::KeySourcejava::awt::event::MouseSourcejava::awt::event::PaintSourcejava::util::PropertyChangeSourcejava::awt::ItemCheckablejava::awt::event::ItemSourcejava::lang::Lockjava::lang::ScopeAdapterjava::lang::Comparablejava::awt::image::ImageObserverjava::util::EventSourcejava::util::Collectionjava::awt::ItemSelectablejava::util::LinkedListjava::util::AbstractSequentialListjava::util::AbstractListjava::util::AbstractCollectionjava::util::List
[legend]

List of all members.


Detailed Description

A check box is a graphical component that can be in either an "on" (true) or "off" (false) state.

Clicking on a check box changes its state from "on" to "off," or from "off" to "on."

The following code example creates a set of check boxes in a grid layout:


<blockquote>
 setLayout(new GridLayout(3, 1));
 add(new Checkbox("one", null, true));
 add(new Checkbox("two"));
 add(new Checkbox("three"));
 
</blockquote>

This image depicts the check boxes and grid layout created by this code example:

Checkbox-1.gif

The button labeled one is in the "on" state, and the other two are in the "off" state. In this example, which uses the GridLayout class, the states of the three check boxes are set independently.

Alternatively, several check boxes can be grouped together under the control of a single object, using the CheckboxGroup class. In a check box group, at most one button can be in the "on" state at any given time. Clicking on a check box to turn it on forces any other check box in the same group that is on into the "off" state.

Version:
1.79 01/23/03
Author:
Sami Shaio
See also:
java.awt.GridLayout

java.awt.CheckboxGroup

Since:
JDK1.0

Public Member Functions

 Checkbox (const String &label=nilString, jboolean state=false, const Ref< CheckboxGroup > &group=0)
 Constructs a Checkbox with the specified label, set to the specified state, and in the specified check box group.
virtual Ref< ListgetSelectedObjects () const
 Returns an array (length 1) containing the checkbox label or null if the checkbox is not selected.
virtual String getLabel () const
 Gets the label of this check box.
virtual void setLabel (const String &label)
 Sets this check box's label to be the string argument.
virtual void setState (jboolean state)
 Sets the state of this check box to the specified state.
virtual void setCheckboxGroup (Ref< CheckboxGroup > &g)
 Sets this check box's group to be the specified check box group.
virtual String toString () const
 Returns a string representation of this component and its values.

Protected Attributes

 REGISTER_MEMBERS

Constructor & Destructor Documentation

java::awt::Checkbox::Checkbox ( const String label = nilString,
jboolean  state = false,
const Ref< CheckboxGroup > &  group = 0 
)

Constructs a Checkbox with the specified label, set to the specified state, and in the specified check box group.

Parameters:
label a string label for this check box, or null for no label.
state the initial state of this check box.
group a check box group for this check box, or null for no group.
Exceptions:
HeadlessException if GraphicsEnvironment.isHeadless returns true
See also:
java.awt.GraphicsEnvironment::isHeadless
Since:
JDK1.1


Member Function Documentation

virtual Ref<List> java::awt::Checkbox::getSelectedObjects (  )  const [virtual]

Returns an array (length 1) containing the checkbox label or null if the checkbox is not selected.

See also:
ItemSelectable

Implements java::awt::ItemSelectable.

virtual String java::awt::Checkbox::getLabel (  )  const [virtual]

Gets the label of this check box.

Returns:
the label of this check box, or null if this check box has no label.
See also:
setLabel(String)

virtual void java::awt::Checkbox::setLabel ( const String label  )  [virtual]

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

Parameters:
label a string to set as the new label, or null for no label.
See also:
getLabel

virtual void java::awt::Checkbox::setState ( jboolean  state  )  [virtual]

Sets the state of this check box to the specified state.

The boolean value true indicates the "on" state, and false indicates the "off" state.

Note that this method should be primarily used to initialize the state of the checkbox. Programmatically setting the state of the checkbox will not trigger an ItemEvent. The only way to trigger an ItemEvent is by user interaction.

Parameters:
state the boolean state of the check box
See also:
getState

Reimplemented from java::awt::ItemCheckable.

virtual void java::awt::Checkbox::setCheckboxGroup ( Ref< CheckboxGroup > &  g  )  [virtual]

Sets this check box's group 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. If the state of this check box is true and the new group already has a check box selected, this check box's state is changed to false.

Parameters:
g the new check box group, or null to remove this check box from any check box group.
See also:
getCheckboxGroup

Reimplemented from java::awt::ItemCheckable.

virtual String java::awt::Checkbox::toString (  )  const [virtual]

Returns a string representation of this component and its values.

Returns:
a string representation of this component
Since:
JDK1.0

Reimplemented from java::awt::Component.


Member Data Documentation

java::awt::Checkbox::REGISTER_MEMBERS [protected]

Reimplemented from java::awt::Component.


The documentation for this class was generated from the following file:
Generated on Fri May 16 11:55:53 2008 for CrossPlatformJavaLikeC++API by  doxygen 1.5.3