Contents | Package | Class | Tree | Deprecated | Index | Help | Java 1.2 Beta 3 | ||
PREV | NEXT | SHOW LISTS | HIDE LISTS |
java.lang.Object | +----java.awt.Component | +----java.awt.Checkbox
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:
setLayout(new GridLayout(3, 1)); add(new Checkbox("one", null, true)); add(new Checkbox("two")); add(new Checkbox("three"));
This image depicts the check boxes and grid layout created by this code example:
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.
Fields inherited from class java.awt.Component |
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT |
Constructor Summary | |
Checkbox()
|
|
Checkbox(String label)
|
|
Checkbox(String label,
boolean state)
|
|
Checkbox(String label,
boolean state,
CheckboxGroup group)
|
|
Checkbox(String label,
CheckboxGroup group,
boolean state)
|
Method Summary | |
void | addItemListener(ItemListener l)
|
void | addNotify()
|
CheckboxGroup | getCheckboxGroup()
|
String | getLabel()
|
Object[] | getSelectedObjects()
|
boolean | getState()
|
String | paramString()
|
void | processEvent(AWTEvent e)
|
void | processItemEvent(ItemEvent e)
ItemListener objects.
|
void | removeItemListener(ItemListener l)
|
void | setCheckboxGroup(CheckboxGroup g)
|
void | setLabel(String label)
|
void | setState(boolean state)
|
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
public Checkbox()
public Checkbox(String label)
label
- a string label for this check box,
or null
for no label.
public Checkbox(String label, boolean state)
state
argument, and it is not part of any check box group.
label
- a string label for this check box,
or null
for no label.
state
- the initial state of this check box.
public Checkbox(String label, boolean state, CheckboxGroup group)
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.
public Checkbox(String label, CheckboxGroup group, boolean state)
Method Detail |
public void addNotify()
public String getLabel()
null
if this check box has no label.public void setLabel(String label)
label
- a string to set as the new label, or
null
for no label.
public boolean getState()
true
indicates the "on" state,
and false
indicates the "off" state.public void setState(boolean state)
true
indicates the "on" state,
and false
indicates the "off" state.
state
- the boolean state of the check box.
public Object[] getSelectedObjects()
public CheckboxGroup getCheckboxGroup()
null
if the check box is not part of a check box group.public void setCheckboxGroup(CheckboxGroup g)
g
- the new check box group, or null
to remove this check box from any check box group.
public void addItemListener(ItemListener l)
l
- the item listener.
public void removeItemListener(ItemListener l)
l
- the item listener.
protected void processEvent(AWTEvent e)
ItemEvent
,
this method invokes the processItemEvent
method.
Otherwise, it calls its superclass's processEvent
method.
e
- the event.
protected void processItemEvent(ItemEvent e)
ItemListener
objects.
This method is not called unless item events are enabled for this component. Item events are enabled when one of the following occurs:
ItemListener
object is registered
via addItemListener
.
enableEvents
.
e
- the item event.
protected String paramString()
Contents | Package | Class | Tree | Deprecated | Index | Help | Java 1.2 Beta 3 | ||
PREV | NEXT | SHOW LISTS | HIDE LISTS |