Spec-Zone .ru
спецификации, руководства, описания, API
JavaTM 2 Platform
Std. Ed. v1.3.1

java.awt
Class CheckboxMenuItem

java.lang.Object
  |
  +--java.awt.MenuComponent
        |
        +--java.awt.MenuItem
              |
              +--java.awt.CheckboxMenuItem
All Implemented Interfaces:
Accessible, ItemSelectable, Serializable

public class CheckboxMenuItem
extends MenuItem
implements ItemSelectable, Accessible

This class represents a check box that can be included in a menu. Clicking on the check box in the menu changes its state from "on" to "off" or from "off" to "on."

The following picture depicts a menu which contains an instance of CheckBoxMenuItem:

The item labeled Check shows a check box menu item in its "off" state.

When a check box menu item is selected, AWT sends an item event to the item. Since the event is an instance of ItemEvent, the processEvent method examines the event and passes it along to processItemEvent. The latter method redirects the event to any ItemListener objects that have registered an interest in item events generated by this menu item.

Since:
JDK1.0
See Also:
ItemEvent, ItemListener, Serialized Form

Inner Class Summary
protected  class CheckboxMenuItem.AccessibleAWTCheckboxMenuItem
          Inner class of CheckboxMenuItem used to provide default support for accessibility.
 
Inner classes inherited from class java.awt.MenuItem
MenuItem.AccessibleAWTMenuItem
 
Inner classes inherited from class java.awt.MenuComponent
MenuComponent.AccessibleAWTMenuComponent
 
Constructor Summary
CheckboxMenuItem()
          Create a check box menu item with an empty label.
CheckboxMenuItem(String label)
          Create a check box menu item with the specified label.
CheckboxMenuItem(String label, boolean state)
          Create a check box menu item with the specified label and state.
 
Method Summary
 void addItemListener(ItemListener l)
          Adds the specified item listener to receive item events from this check box menu item.
 void addNotify()
          Creates the peer of the checkbox item.
 AccessibleContext getAccessibleContext()
          Gets the AccessibleContext associated with this CheckboxMenuItem.
 EventListener[] getListeners(Class listenerType)
          Return an array of all the listeners that were added to the CheckboxMenuItem with addXXXListener(), where XXX is the name of the listenerType argument.
 Object[] getSelectedObjects()
          Returns the an array (length 1) containing the checkbox menu item label or null if the checkbox is not selected.
 boolean getState()
          Determines whether the state of this check box menu item is "on" or "off."
 String paramString()
          Returns the parameter string representing the state of this check box menu item.
protected  void processEvent(AWTEvent e)
          Processes events on this check box menu item.
protected  void processItemEvent(ItemEvent e)
          Processes item events occurring on this check box menu item by dispatching them to any registered ItemListener objects.
 void removeItemListener(ItemListener l)
          Removes the specified item listener so that it no longer receives item events from this check box menu item.
 void setState(boolean b)
          Sets this check box menu item to the specifed state.
 
Methods inherited from class java.awt.MenuItem
addActionListener, deleteShortcut, disable, disableEvents, enable, enable, enableEvents, getActionCommand, getLabel, getShortcut, isEnabled, processActionEvent, removeActionListener, setActionCommand, setEnabled, setLabel, setShortcut
 
Methods inherited from class java.awt.MenuComponent
dispatchEvent, getFont, getName, getParent, getPeer, getTreeLock, postEvent, removeNotify, setFont, setName, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

CheckboxMenuItem

public CheckboxMenuItem()
Create a check box menu item with an empty label. The item's state is initially set to "off."
Since:
JDK1.1

CheckboxMenuItem

public CheckboxMenuItem(String label)
Create a check box menu item with the specified label. The item's state is initially set to "off."
Parameters:
label - a string label for the check box menu item, or null for an unlabeled menu item.

CheckboxMenuItem

public CheckboxMenuItem(String label,
                        boolean state)
Create a check box menu item with the specified label and state.
Parameters:
label - a string label for the check box menu item, or null for an unlabeled menu item.
state - the initial state of the menu item, where true indicates "on" and false indicates "off."
Since:
JDK1.1
Method Detail

addNotify

public void addNotify()
Creates the peer of the checkbox item. This peer allows us to change the look of the checkbox item without changing its functionality. Most applications do not call this method directly.
Overrides:
addNotify in class MenuItem
See Also:
Toolkit.createCheckboxMenuItem(java.awt.CheckboxMenuItem), Component.getToolkit()

getState

public boolean getState()
Determines whether the state of this check box menu item is "on" or "off."
Returns:
the state of this check box menu item, where true indicates "on" and false indicates "off."
See Also:
setState(boolean)

setState

public void setState(boolean b)
Sets this check box menu item to the specifed state. The boolean value true indicates "on" while false indicates "off."
Parameters:
b - the boolean state of this check box menu item.
See Also:
getState()

getSelectedObjects

public Object[] getSelectedObjects()
Returns the an array (length 1) containing the checkbox menu item label or null if the checkbox is not selected.
Specified by:
getSelectedObjects in interface ItemSelectable
See Also:
ItemSelectable

addItemListener

public void addItemListener(ItemListener l)
Adds the specified item listener to receive item events from this check box menu item. If l is null, no exception is thrown and no action is performed.
Specified by:
addItemListener in interface ItemSelectable
Parameters:
l - the item listener
Since:
JDK1.1
See Also:
ItemEvent, ItemListener, Choice.removeItemListener(java.awt.event.ItemListener)

removeItemListener

public void removeItemListener(ItemListener l)
Removes the specified item listener so that it no longer receives item events from this check box menu item. If l is null, no exception is thrown and no action is performed.
Specified by:
removeItemListener in interface ItemSelectable
Parameters:
l - the item listener
Since:
JDK1.1
See Also:
ItemEvent, ItemListener, Choice.addItemListener(java.awt.event.ItemListener)

getListeners

public EventListener[] getListeners(Class listenerType)
Return an array of all the listeners that were added to the CheckboxMenuItem with addXXXListener(), where XXX is the name of the listenerType argument. For example, to get all of the ItemListener(s) for the given CheckboxMenuItem c, one would write:
 ItemListener[] ils = (ItemListener[])(c.getListeners(ItemListener.class))
 
If no such listener list exists, then an empty array is returned.
Overrides:
getListeners in class MenuItem
Parameters:
listenerType - Type of listeners requested
Returns:
all of the listeners of the specified type supported by this checkbox menu item
Since:
1.3

processEvent

protected void processEvent(AWTEvent e)
Processes events on this check box menu item. If the event is an instance of ItemEvent, this method invokes the processItemEvent method. If the event is not an item event, it invokes processEvent on the superclass.

Check box menu items currently support only item events.

Overrides:
processEvent in class MenuItem
Parameters:
e - the event
Since:
JDK1.1
See Also:
ItemEvent, processItemEvent(java.awt.event.ItemEvent)

processItemEvent

protected void processItemEvent(ItemEvent e)
Processes item events occurring on this check box menu item by dispatching them to any registered ItemListener objects.

This method is not called unless item events are enabled for this menu item. Item events are enabled when one of the following occurs:

Parameters:
e - the item event.
Since:
JDK1.1
See Also:
ItemEvent, ItemListener, addItemListener(java.awt.event.ItemListener), MenuItem.enableEvents(long)

paramString

public String paramString()
Returns the parameter string representing the state of this check box menu item. This string is useful for debugging.
Overrides:
paramString in class MenuItem
Returns:
the parameter string of this check box menu item.

getAccessibleContext

public AccessibleContext getAccessibleContext()
Gets the AccessibleContext associated with this CheckboxMenuItem. For checkbox menu items, the AccessibleContext takes the form of an AccessibleAWTCheckboxMenuItem. A new AccessibleAWTCheckboxMenuItem is created if necessary.
Specified by:
getAccessibleContext in interface Accessible
Overrides:
getAccessibleContext in class MenuItem
Returns:
an AccessibleAWTCheckboxMenuItem that serves as the AccessibleContext of this CheckboxMenuItem

JavaTM 2 Platform
Std. Ed. v1.3.1

Submit a bug or feature
For further API reference and developer documentation, see Java 2 SDK SE Developer Documentation. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples.

Java, Java 2D, and JDBC are trademarks or registered trademarks of Sun Microsystems, Inc. in the US and other countries.
Copyright 1993-2001 Sun Microsystems, Inc. 901 San Antonio Road
Palo Alto, California, 94303, U.S.A. All Rights Reserved.

free hit counter