< prev index next >
src/java.desktop/share/classes/java/awt/Checkbox.java
Print this page
*** 33,43 ****
import javax.accessibility.*;
/**
* A check box is a graphical component that can be in either an
! * "on" (<code>true</code>) or "off" (<code>false</code>) state.
* Clicking on a check box changes its state from
* "on" to "off," or from "off" to "on."
* <p>
* The following code example creates a set of check boxes in
* a grid layout:
--- 33,43 ----
import javax.accessibility.*;
/**
* A check box is a graphical component that can be in either an
! * "on" ({@code true}) or "off" ({@code false}) state.
* Clicking on a check box changes its state from
* "on" to "off," or from "off" to "on."
* <p>
* The following code example creates a set of check boxes in
* a grid layout:
*** 53,70 ****
* created by this code example:
* <p>
* <img src="doc-files/Checkbox-1.gif" alt="The following context describes the graphic."
* style="float:center; margin: 7px 10px;">
* <p>
! * The button labeled <code>one</code> is in the "on" state, and the
* other two are in the "off" state. In this example, which uses the
! * <code>GridLayout</code> class, the states of the three check
* boxes are set independently.
* <p>
* Alternatively, several check boxes can be grouped together under
* the control of a single object, using the
! * <code>CheckboxGroup</code> 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.
*
--- 53,70 ----
* created by this code example:
* <p>
* <img src="doc-files/Checkbox-1.gif" alt="The following context describes the graphic."
* style="float:center; margin: 7px 10px;">
* <p>
! * The button labeled {@code one} is in the "on" state, and the
* other two are in the "off" state. In this example, which uses the
! * {@code GridLayout} class, the states of the three check
* boxes are set independently.
* <p>
* Alternatively, several check boxes can be grouped together under
* the control of a single object, using the
! * {@code 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.
*
*** 91,101 ****
* @see #setLabel(String)
*/
String label;
/**
! * The state of the <code>Checkbox</code>.
* @serial
* @see #getState()
* @see #setState(boolean)
*/
boolean state;
--- 91,101 ----
* @see #setLabel(String)
*/
String label;
/**
! * The state of the {@code Checkbox}.
* @serial
* @see #getState()
* @see #setState(boolean)
*/
boolean state;
*** 148,161 ****
* Creates a check box with the specified label. The state
* of this check box is set to "off," and it is not part of
* any check box group.
*
* @param label a string label for this check box,
! * or <code>null</code> for no label.
* @exception HeadlessException if
! * <code>GraphicsEnvironment.isHeadless</code>
! * returns <code>true</code>
* @see java.awt.GraphicsEnvironment#isHeadless
*/
public Checkbox(String label) throws HeadlessException {
this(label, false, null);
}
--- 148,161 ----
* Creates a check box with the specified label. The state
* of this check box is set to "off," and it is not part of
* any check box group.
*
* @param label a string label for this check box,
! * or {@code null} for no label.
* @exception HeadlessException if
! * {@code GraphicsEnvironment.isHeadless}
! * returns {@code true}
* @see java.awt.GraphicsEnvironment#isHeadless
*/
public Checkbox(String label) throws HeadlessException {
this(label, false, null);
}
*** 164,178 ****
* Creates a check box with the specified label
* and sets the specified state.
* This check box is not part of any check box group.
*
* @param label a string label for this check box,
! * or <code>null</code> for no label
* @param state the initial state of this check box
* @exception HeadlessException if
! * <code>GraphicsEnvironment.isHeadless</code>
! * returns <code>true</code>
* @see java.awt.GraphicsEnvironment#isHeadless
*/
public Checkbox(String label, boolean state) throws HeadlessException {
this(label, state, null);
}
--- 164,178 ----
* Creates a check box with the specified label
* and sets the specified state.
* This check box is not part of any check box group.
*
* @param label a string label for this check box,
! * or {@code null} for no label
* @param state the initial state of this check box
* @exception HeadlessException if
! * {@code GraphicsEnvironment.isHeadless}
! * returns {@code true}
* @see java.awt.GraphicsEnvironment#isHeadless
*/
public Checkbox(String label, boolean state) throws HeadlessException {
this(label, state, null);
}
*** 180,196 ****
/**
* Constructs a Checkbox with the specified label, set to the
* specified state, and in the specified check box group.
*
* @param label a string label for this check box,
! * or <code>null</code> for no label.
* @param state the initial state of this check box.
* @param group a check box group for this check box,
! * or <code>null</code> for no group.
* @exception HeadlessException if
! * <code>GraphicsEnvironment.isHeadless</code>
! * returns <code>true</code>
* @see java.awt.GraphicsEnvironment#isHeadless
* @since 1.1
*/
public Checkbox(String label, boolean state, CheckboxGroup group)
throws HeadlessException {
--- 180,196 ----
/**
* Constructs a Checkbox with the specified label, set to the
* specified state, and in the specified check box group.
*
* @param label a string label for this check box,
! * or {@code null} for no label.
* @param state the initial state of this check box.
* @param group a check box group for this check box,
! * or {@code null} for no group.
* @exception HeadlessException if
! * {@code GraphicsEnvironment.isHeadless}
! * returns {@code true}
* @see java.awt.GraphicsEnvironment#isHeadless
* @since 1.1
*/
public Checkbox(String label, boolean state, CheckboxGroup group)
throws HeadlessException {
*** 206,233 ****
/**
* Creates a check box with the specified label, in the specified
* check box group, and set to the specified state.
*
* @param label a string label for this check box,
! * or <code>null</code> for no label.
* @param group a check box group for this check box,
! * or <code>null</code> for no group.
* @param state the initial state of this check box.
* @exception HeadlessException if
! * <code>GraphicsEnvironment.isHeadless</code>
! * returns <code>true</code>
* @see java.awt.GraphicsEnvironment#isHeadless
* @since 1.1
*/
public Checkbox(String label, CheckboxGroup group, boolean state)
throws HeadlessException {
this(label, state, group);
}
/**
* Constructs a name for this component. Called by
! * <code>getName</code> when the name is <code>null</code>.
*
* @return a name for this component
*/
String constructComponentName() {
synchronized (Checkbox.class) {
--- 206,233 ----
/**
* Creates a check box with the specified label, in the specified
* check box group, and set to the specified state.
*
* @param label a string label for this check box,
! * or {@code null} for no label.
* @param group a check box group for this check box,
! * or {@code null} for no group.
* @param state the initial state of this check box.
* @exception HeadlessException if
! * {@code GraphicsEnvironment.isHeadless}
! * returns {@code true}
* @see java.awt.GraphicsEnvironment#isHeadless
* @since 1.1
*/
public Checkbox(String label, CheckboxGroup group, boolean state)
throws HeadlessException {
this(label, state, group);
}
/**
* Constructs a name for this component. Called by
! * {@code getName} when the name is {@code null}.
*
* @return a name for this component
*/
String constructComponentName() {
synchronized (Checkbox.class) {
*** 250,260 ****
}
/**
* Gets the label of this check box.
*
! * @return the label of this check box, or <code>null</code>
* if this check box has no label.
* @see #setLabel(String)
*/
public String getLabel() {
return label;
--- 250,260 ----
}
/**
* Gets the label of this check box.
*
! * @return the label of this check box, or {@code null}
* if this check box has no label.
* @see #setLabel(String)
*/
public String getLabel() {
return label;
*** 262,272 ****
/**
* Sets this check box's label to be the string argument.
*
* @param label a string to set as the new label, or
! * <code>null</code> for no label.
* @see #getLabel
*/
public void setLabel(String label) {
boolean testvalid = false;
--- 262,272 ----
/**
* Sets this check box's label to be the string argument.
*
* @param label a string to set as the new label, or
! * {@code null} for no label.
* @see #getLabel
*/
public void setLabel(String label) {
boolean testvalid = false;
*** 288,317 ****
}
}
/**
* Determines whether this check box is in the "on" or "off" state.
! * The boolean value <code>true</code> indicates the "on" state,
! * and <code>false</code> indicates the "off" state.
*
* @return the state of this check box, as a boolean value
* @see #setState
*/
public boolean getState() {
return state;
}
/**
* Sets the state of this check box to the specified state.
! * The boolean value <code>true</code> indicates the "on" state,
! * and <code>false</code> indicates the "off" state.
*
* <p>Note that this method should be primarily used to
* initialize the state of the checkbox. Programmatically
* setting the state of the checkbox will <i>not</i> trigger
! * an <code>ItemEvent</code>. The only way to trigger an
! * <code>ItemEvent</code> is by user interaction.
*
* @param state the boolean state of the check box
* @see #getState
*/
public void setState(boolean state) {
--- 288,317 ----
}
}
/**
* Determines whether this check box is in the "on" or "off" state.
! * The boolean value {@code true} indicates the "on" state,
! * and {@code false} indicates the "off" state.
*
* @return the state of this check box, as a boolean value
* @see #setState
*/
public boolean getState() {
return state;
}
/**
* Sets the state of this check box to the specified state.
! * The boolean value {@code true} indicates the "on" state,
! * and {@code false} indicates the "off" state.
*
* <p>Note that this method should be primarily used to
* initialize the state of the checkbox. Programmatically
* setting the state of the checkbox will <i>not</i> trigger
! * an {@code ItemEvent}. The only way to trigger an
! * {@code ItemEvent} is by user interaction.
*
* @param state the boolean state of the check box
* @see #getState
*/
public void setState(boolean state) {
*** 341,351 ****
return null;
}
/**
* Determines this check box's group.
! * @return this check box's group, or <code>null</code>
* if the check box is not part of a check box group.
* @see #setCheckboxGroup(CheckboxGroup)
*/
public CheckboxGroup getCheckboxGroup() {
return group;
--- 341,351 ----
return null;
}
/**
* Determines this check box's group.
! * @return this check box's group, or {@code null}
* if the check box is not part of a check box group.
* @see #setCheckboxGroup(CheckboxGroup)
*/
public CheckboxGroup getCheckboxGroup() {
return group;
*** 354,371 ****
/**
* Sets this check box's group to 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.
* <p>
! * If the state of this check box is <code>true</code> and the new
* group already has a check box selected, this check box's state
! * is changed to <code>false</code>. If the state of this check
! * box is <code>true</code> and the new group has no check box
* selected, this check box becomes the selected checkbox for
! * the new group and its state is <code>true</code>.
*
! * @param g the new check box group, or <code>null</code>
* to remove this check box from any check box group
* @see #getCheckboxGroup
*/
public void setCheckboxGroup(CheckboxGroup g) {
CheckboxGroup oldGroup;
--- 354,371 ----
/**
* Sets this check box's group to 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.
* <p>
! * If the state of this check box is {@code true} and the new
* group already has a check box selected, this check box's state
! * is changed to {@code false}. If the state of this check
! * box is {@code true} and the new group has no check box
* selected, this check box becomes the selected checkbox for
! * the new group and its state is {@code true}.
*
! * @param g the new check box group, or {@code null}
* to remove this check box from any check box group
* @see #getCheckboxGroup
*/
public void setCheckboxGroup(CheckboxGroup g) {
CheckboxGroup oldGroup;
*** 456,466 ****
/**
* Returns an array of all the item listeners
* registered on this checkbox.
*
! * @return all of this checkbox's <code>ItemListener</code>s
* or an empty array if no item
* listeners are currently registered
*
* @see #addItemListener
* @see #removeItemListener
--- 456,466 ----
/**
* Returns an array of all the item listeners
* registered on this checkbox.
*
! * @return all of this checkbox's {@code ItemListener}s
* or an empty array if no item
* listeners are currently registered
*
* @see #addItemListener
* @see #removeItemListener
*** 473,508 ****
}
/**
* Returns an array of all the objects currently registered
* as <code><em>Foo</em>Listener</code>s
! * upon this <code>Checkbox</code>.
* <code><em>Foo</em>Listener</code>s are registered using the
* <code>add<em>Foo</em>Listener</code> method.
*
* <p>
! * You can specify the <code>listenerType</code> argument
* with a class literal, such as
* <code><em>Foo</em>Listener.class</code>.
* For example, you can query a
! * <code>Checkbox</code> <code>c</code>
* for its item listeners with the following code:
*
* <pre>ItemListener[] ils = (ItemListener[])(c.getListeners(ItemListener.class));</pre>
*
* If no such listeners exist, this method returns an empty array.
*
* @param listenerType the type of listeners requested; this parameter
* should specify an interface that descends from
! * <code>java.util.EventListener</code>
* @return an array of all objects registered as
* <code><em>Foo</em>Listener</code>s on this checkbox,
* or an empty array if no such
* listeners have been added
! * @exception ClassCastException if <code>listenerType</code>
* doesn't specify a class or interface that implements
! * <code>java.util.EventListener</code>
*
* @see #getItemListeners
* @since 1.3
*/
public <T extends EventListener> T[] getListeners(Class<T> listenerType) {
--- 473,508 ----
}
/**
* Returns an array of all the objects currently registered
* as <code><em>Foo</em>Listener</code>s
! * upon this {@code Checkbox}.
* <code><em>Foo</em>Listener</code>s are registered using the
* <code>add<em>Foo</em>Listener</code> method.
*
* <p>
! * You can specify the {@code listenerType} argument
* with a class literal, such as
* <code><em>Foo</em>Listener.class</code>.
* For example, you can query a
! * {@code Checkbox c}
* for its item listeners with the following code:
*
* <pre>ItemListener[] ils = (ItemListener[])(c.getListeners(ItemListener.class));</pre>
*
* If no such listeners exist, this method returns an empty array.
*
* @param listenerType the type of listeners requested; this parameter
* should specify an interface that descends from
! * {@code java.util.EventListener}
* @return an array of all objects registered as
* <code><em>Foo</em>Listener</code>s on this checkbox,
* or an empty array if no such
* listeners have been added
! * @exception ClassCastException if {@code listenerType}
* doesn't specify a class or interface that implements
! * {@code java.util.EventListener}
*
* @see #getItemListeners
* @since 1.3
*/
public <T extends EventListener> T[] getListeners(Class<T> listenerType) {
*** 527,540 ****
return super.eventEnabled(e);
}
/**
* Processes events on this check box.
! * If the event is an instance of <code>ItemEvent</code>,
! * this method invokes the <code>processItemEvent</code> method.
! * Otherwise, it calls its superclass's <code>processEvent</code> method.
! * <p>Note that if the event parameter is <code>null</code>
* the behavior is unspecified and may result in an
* exception.
*
* @param e the event
* @see java.awt.event.ItemEvent
--- 527,540 ----
return super.eventEnabled(e);
}
/**
* Processes events on this check box.
! * If the event is an instance of {@code ItemEvent},
! * this method invokes the {@code processItemEvent} method.
! * Otherwise, it calls its superclass's {@code processEvent} method.
! * <p>Note that if the event parameter is {@code null}
* the behavior is unspecified and may result in an
* exception.
*
* @param e the event
* @see java.awt.event.ItemEvent
*** 550,570 ****
}
/**
* Processes item events occurring on this check box by
* dispatching them to any registered
! * <code>ItemListener</code> objects.
* <p>
* This method is not called unless item events are
* enabled for this component. Item events are enabled
* when one of the following occurs:
* <ul>
! * <li>An <code>ItemListener</code> object is registered
! * via <code>addItemListener</code>.
! * <li>Item events are enabled via <code>enableEvents</code>.
* </ul>
! * <p>Note that if the event parameter is <code>null</code>
* the behavior is unspecified and may result in an
* exception.
*
* @param e the item event
* @see java.awt.event.ItemEvent
--- 550,570 ----
}
/**
* Processes item events occurring on this check box by
* dispatching them to any registered
! * {@code ItemListener} objects.
* <p>
* This method is not called unless item events are
* enabled for this component. Item events are enabled
* when one of the following occurs:
* <ul>
! * <li>An {@code ItemListener} object is registered
! * via {@code addItemListener}.
! * <li>Item events are enabled via {@code enableEvents}.
* </ul>
! * <p>Note that if the event parameter is {@code null}
* the behavior is unspecified and may result in an
* exception.
*
* @param e the item event
* @see java.awt.event.ItemEvent
*** 579,593 ****
listener.itemStateChanged(e);
}
}
/**
! * Returns a string representing the state of this <code>Checkbox</code>.
* This method is intended to be used only for debugging purposes, and the
* content and format of the returned string may vary between
* implementations. The returned string may be empty but may not be
! * <code>null</code>.
*
* @return the parameter string of this check box
*/
protected String paramString() {
String str = super.paramString();
--- 579,593 ----
listener.itemStateChanged(e);
}
}
/**
! * Returns a string representing the state of this {@code Checkbox}.
* This method is intended to be used only for debugging purposes, and the
* content and format of the returned string may vary between
* implementations. The returned string may be empty but may not be
! * {@code null}.
*
* @return the parameter string of this check box
*/
protected String paramString() {
String str = super.paramString();
*** 608,629 ****
*/
private int checkboxSerializedDataVersion = 1;
/**
* Writes default serializable fields to stream. Writes
! * a list of serializable <code>ItemListeners</code>
* as optional data. The non-serializable
! * <code>ItemListeners</code> are detected and
* no attempt is made to serialize them.
*
! * @param s the <code>ObjectOutputStream</code> to write
! * @serialData <code>null</code> terminated sequence of 0
! * or more pairs; the pair consists of a <code>String</code>
! * and an <code>Object</code>; the <code>String</code> indicates
* the type of object and is one of the following:
! * <code>itemListenerK</code> indicating an
! * <code>ItemListener</code> object
*
* @see AWTEventMulticaster#save(ObjectOutputStream, String, EventListener)
* @see java.awt.Component#itemListenerK
* @see #readObject(ObjectInputStream)
*/
--- 608,629 ----
*/
private int checkboxSerializedDataVersion = 1;
/**
* Writes default serializable fields to stream. Writes
! * a list of serializable {@code ItemListeners}
* as optional data. The non-serializable
! * {@code ItemListeners} are detected and
* no attempt is made to serialize them.
*
! * @param s the {@code ObjectOutputStream} to write
! * @serialData {@code null} terminated sequence of 0
! * or more pairs; the pair consists of a {@code String}
! * and an {@code Object}; the {@code String} indicates
* the type of object and is one of the following:
! * {@code itemListenerK} indicating an
! * {@code ItemListener} object
*
* @see AWTEventMulticaster#save(ObjectOutputStream, String, EventListener)
* @see java.awt.Component#itemListenerK
* @see #readObject(ObjectInputStream)
*/
*** 635,653 ****
AWTEventMulticaster.save(s, itemListenerK, itemListener);
s.writeObject(null);
}
/**
! * Reads the <code>ObjectInputStream</code> and if it
! * isn't <code>null</code> adds a listener to receive
! * item events fired by the <code>Checkbox</code>.
* Unrecognized keys or values will be ignored.
*
! * @param s the <code>ObjectInputStream</code> to read
* @exception HeadlessException if
! * <code>GraphicsEnvironment.isHeadless</code> returns
! * <code>true</code>
* @serial
* @see #removeItemListener(ItemListener)
* @see #addItemListener(ItemListener)
* @see java.awt.GraphicsEnvironment#isHeadless
* @see #writeObject(ObjectOutputStream)
--- 635,653 ----
AWTEventMulticaster.save(s, itemListenerK, itemListener);
s.writeObject(null);
}
/**
! * Reads the {@code ObjectInputStream} and if it
! * isn't {@code null} adds a listener to receive
! * item events fired by the {@code Checkbox}.
* Unrecognized keys or values will be ignored.
*
! * @param s the {@code ObjectInputStream} to read
* @exception HeadlessException if
! * {@code GraphicsEnvironment.isHeadless} returns
! * {@code true}
* @serial
* @see #removeItemListener(ItemListener)
* @see #addItemListener(ItemListener)
* @see java.awt.GraphicsEnvironment#isHeadless
* @see #writeObject(ObjectOutputStream)
*** 698,708 ****
return accessibleContext;
}
/**
* This class implements accessibility support for the
! * <code>Checkbox</code> class. It provides an implementation of the
* Java Accessibility API appropriate to checkbox user-interface elements.
* @since 1.3
*/
protected class AccessibleAWTCheckbox extends AccessibleAWTComponent
implements ItemListener, AccessibleAction, AccessibleValue
--- 698,708 ----
return accessibleContext;
}
/**
* This class implements accessibility support for the
! * {@code Checkbox} class. It provides an implementation of the
* Java Accessibility API appropriate to checkbox user-interface elements.
* @since 1.3
*/
protected class AccessibleAWTCheckbox extends AccessibleAWTComponent
implements ItemListener, AccessibleAction, AccessibleValue
< prev index next >