java.awt
Class MenuItem

java.lang.Object sample code for java.lang.Object definition code for java.lang.Object 
  extended by java.awt.MenuComponent sample code for java.awt.MenuComponent definition code for java.awt.MenuComponent 
      extended by java.awt.MenuItem
All Implemented Interfaces:
Serializable sample code for java.io.Serializable definition code for java.io.Serializable , Accessible sample code for javax.accessibility.Accessible definition code for javax.accessibility.Accessible
Direct Known Subclasses:
CheckboxMenuItem sample code for java.awt.CheckboxMenuItem definition code for java.awt.CheckboxMenuItem , Menu sample code for java.awt.Menu definition code for java.awt.Menu

public class MenuItem
extends MenuComponent sample code for java.awt.MenuComponent definition code for java.awt.MenuComponent
implements Accessible sample code for javax.accessibility.Accessible definition code for javax.accessibility.Accessible

All items in a menu must belong to the class MenuItem, or one of its subclasses.

The default MenuItem object embodies a simple labeled menu item.

This picture of a menu bar shows five menu items: The following text describes this graphic.
The first two items are simple menu items, labeled "Basic" and "Simple". Following these two items is a separator, which is itself a menu item, created with the label "-". Next is an instance of CheckboxMenuItem labeled "Check". The final menu item is a submenu labeled "More Examples", and this submenu is an instance of Menu.

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

Note that the subclass Menu overrides this behavior and does not send any event to the frame until one of its subitems is selected.

See Also:
Serialized Form

Nested Class Summary
protected  class MenuItem.AccessibleAWTMenuItem sample code for java.awt.MenuItem.AccessibleAWTMenuItem definition code for java.awt.MenuItem.AccessibleAWTMenuItem
          Inner class of MenuItem used to provide default support for accessibility.
 
Nested classes/interfaces inherited from class java.awt.MenuComponent sample code for java.awt.MenuComponent definition code for java.awt.MenuComponent
MenuComponent.AccessibleAWTMenuComponent sample code for java.awt.MenuComponent.AccessibleAWTMenuComponent definition code for java.awt.MenuComponent.AccessibleAWTMenuComponent
 
Constructor Summary
MenuItem sample code for java.awt.MenuItem.MenuItem() definition code for java.awt.MenuItem.MenuItem() ()
          Constructs a new MenuItem with an empty label and no keyboard shortcut.
MenuItem sample code for java.awt.MenuItem.MenuItem(java.lang.String) definition code for java.awt.MenuItem.MenuItem(java.lang.String) (String sample code for java.lang.String definition code for java.lang.String  label)
          Constructs a new MenuItem with the specified label and no keyboard shortcut.
MenuItem sample code for java.awt.MenuItem.MenuItem(java.lang.String, java.awt.MenuShortcut) definition code for java.awt.MenuItem.MenuItem(java.lang.String, java.awt.MenuShortcut) (String sample code for java.lang.String definition code for java.lang.String  label, MenuShortcut sample code for java.awt.MenuShortcut definition code for java.awt.MenuShortcut  s)
          Create a menu item with an associated keyboard shortcut.
 
Method Summary
 void addActionListener sample code for java.awt.MenuItem.addActionListener(java.awt.event.ActionListener) definition code for java.awt.MenuItem.addActionListener(java.awt.event.ActionListener) (ActionListener sample code for java.awt.event.ActionListener definition code for java.awt.event.ActionListener  l)
          Adds the specified action listener to receive action events from this menu item.
 void addNotify sample code for java.awt.MenuItem.addNotify() definition code for java.awt.MenuItem.addNotify() ()
          Creates the menu item's peer.
 void deleteShortcut sample code for java.awt.MenuItem.deleteShortcut() definition code for java.awt.MenuItem.deleteShortcut() ()
          Delete any MenuShortcut object associated with this menu item.
 void disable sample code for java.awt.MenuItem.disable() definition code for java.awt.MenuItem.disable() ()
          Deprecated. As of JDK version 1.1, replaced by setEnabled(boolean).
protected  void disableEvents sample code for java.awt.MenuItem.disableEvents(long) definition code for java.awt.MenuItem.disableEvents(long) (long eventsToDisable)
          Disables event delivery to this menu item for events defined by the specified event mask parameter.
 void enable sample code for java.awt.MenuItem.enable() definition code for java.awt.MenuItem.enable() ()
          Deprecated. As of JDK version 1.1, replaced by setEnabled(boolean).
 void enable sample code for java.awt.MenuItem.enable(boolean) definition code for java.awt.MenuItem.enable(boolean) (boolean b)
          Deprecated. As of JDK version 1.1, replaced by setEnabled(boolean).
protected  void enableEvents sample code for java.awt.MenuItem.enableEvents(long) definition code for java.awt.MenuItem.enableEvents(long) (long eventsToEnable)
          Enables event delivery to this menu item for events to be defined by the specified event mask parameter
 AccessibleContext sample code for javax.accessibility.AccessibleContext definition code for javax.accessibility.AccessibleContext getAccessibleContext sample code for java.awt.MenuItem.getAccessibleContext() definition code for java.awt.MenuItem.getAccessibleContext() ()
          Gets the AccessibleContext associated with this MenuItem.
 String sample code for java.lang.String definition code for java.lang.String getActionCommand sample code for java.awt.MenuItem.getActionCommand() definition code for java.awt.MenuItem.getActionCommand() ()
          Gets the command name of the action event that is fired by this menu item.
 ActionListener sample code for java.awt.event.ActionListener definition code for java.awt.event.ActionListener [] getActionListeners sample code for java.awt.MenuItem.getActionListeners() definition code for java.awt.MenuItem.getActionListeners() ()
          Returns an array of all the action listeners registered on this menu item.
 String sample code for java.lang.String definition code for java.lang.String getLabel sample code for java.awt.MenuItem.getLabel() definition code for java.awt.MenuItem.getLabel() ()
          Gets the label for this menu item.
<T extends EventListener sample code for java.util.EventListener definition code for java.util.EventListener >
T[]
getListeners sample code for java.awt.MenuItem.getListeners(java.lang.Class) definition code for java.awt.MenuItem.getListeners(java.lang.Class) (Class sample code for java.lang.Class definition code for java.lang.Class <T> listenerType)
          Returns an array of all the objects currently registered as FooListeners upon this MenuItem.
 MenuShortcut sample code for java.awt.MenuShortcut definition code for java.awt.MenuShortcut getShortcut sample code for java.awt.MenuItem.getShortcut() definition code for java.awt.MenuItem.getShortcut() ()
          Get the MenuShortcut object associated with this menu item,
 boolean isEnabled sample code for java.awt.MenuItem.isEnabled() definition code for java.awt.MenuItem.isEnabled() ()
          Checks whether this menu item is enabled.
 String sample code for java.lang.String definition code for java.lang.String paramString sample code for java.awt.MenuItem.paramString() definition code for java.awt.MenuItem.paramString() ()
          Returns a string representing the state of this MenuItem.
protected  void processActionEvent sample code for java.awt.MenuItem.processActionEvent(java.awt.event.ActionEvent) definition code for java.awt.MenuItem.processActionEvent(java.awt.event.ActionEvent) (ActionEvent sample code for java.awt.event.ActionEvent definition code for java.awt.event.ActionEvent  e)
          Processes action events occurring on this menu item, by dispatching them to any registered ActionListener objects.
protected  void processEvent sample code for java.awt.MenuItem.processEvent(java.awt.AWTEvent) definition code for java.awt.MenuItem.processEvent(java.awt.AWTEvent) (AWTEvent sample code for java.awt.AWTEvent definition code for java.awt.AWTEvent  e)
          Processes events on this menu item.
 void removeActionListener sample code for java.awt.MenuItem.removeActionListener(java.awt.event.ActionListener) definition code for java.awt.MenuItem.removeActionListener(java.awt.event.ActionListener) (ActionListener sample code for java.awt.event.ActionListener definition code for java.awt.event.ActionListener  l)
          Removes the specified action listener so it no longer receives action events from this menu item.
 void setActionCommand sample code for java.awt.MenuItem.setActionCommand(java.lang.String) definition code for java.awt.MenuItem.setActionCommand(java.lang.String) (String sample code for java.lang.String definition code for java.lang.String  command)
          Sets the command name of the action event that is fired by this menu item.
 void setEnabled sample code for java.awt.MenuItem.setEnabled(boolean) definition code for java.awt.MenuItem.setEnabled(boolean) (boolean b)
          Sets whether or not this menu item can be chosen.
 void setLabel sample code for java.awt.MenuItem.setLabel(java.lang.String) definition code for java.awt.MenuItem.setLabel(java.lang.String) (String sample code for java.lang.String definition code for java.lang.String  label)
          Sets the label for this menu item to the specified label.
 void setShortcut sample code for java.awt.MenuItem.setShortcut(java.awt.MenuShortcut) definition code for java.awt.MenuItem.setShortcut(java.awt.MenuShortcut) (MenuShortcut sample code for java.awt.MenuShortcut definition code for java.awt.MenuShortcut  s)
          Set the MenuShortcut object associated with this menu item.
 
Methods inherited from class java.awt.MenuComponent sample code for java.awt.MenuComponent definition code for java.awt.MenuComponent
dispatchEvent sample code for java.awt.MenuComponent.dispatchEvent(java.awt.AWTEvent) definition code for java.awt.MenuComponent.dispatchEvent(java.awt.AWTEvent) , getFont sample code for java.awt.MenuComponent.getFont() definition code for java.awt.MenuComponent.getFont() , getName sample code for java.awt.MenuComponent.getName() definition code for java.awt.MenuComponent.getName() , getParent sample code for java.awt.MenuComponent.getParent() definition code for java.awt.MenuComponent.getParent() , getPeer sample code for java.awt.MenuComponent.getPeer() definition code for java.awt.MenuComponent.getPeer() , getTreeLock sample code for java.awt.MenuComponent.getTreeLock() definition code for java.awt.MenuComponent.getTreeLock() , postEvent sample code for java.awt.MenuComponent.postEvent(java.awt.Event) definition code for java.awt.MenuComponent.postEvent(java.awt.Event) , removeNotify sample code for java.awt.MenuComponent.removeNotify() definition code for java.awt.MenuComponent.removeNotify() , setFont sample code for java.awt.MenuComponent.setFont(java.awt.Font) definition code for java.awt.MenuComponent.setFont(java.awt.Font) , setName sample code for java.awt.MenuComponent.setName(java.lang.String) definition code for java.awt.MenuComponent.setName(java.lang.String) , toString sample code for java.awt.MenuComponent.toString() definition code for java.awt.MenuComponent.toString()
 
Methods inherited from class java.lang.Object sample code for java.lang.Object definition code for java.lang.Object
clone sample code for java.lang.Object.clone() definition code for java.lang.Object.clone() , equals sample code for java.lang.Object.equals(java.lang.Object) definition code for java.lang.Object.equals(java.lang.Object) , finalize sample code for java.lang.Object.finalize() definition code for java.lang.Object.finalize() , getClass sample code for java.lang.Object.getClass() definition code for java.lang.Object.getClass() , hashCode sample code for java.lang.Object.hashCode() definition code for java.lang.Object.hashCode() , notify sample code for java.lang.Object.notify() definition code for java.lang.Object.notify() , notifyAll sample code for java.lang.Object.notifyAll() definition code for java.lang.Object.notifyAll() , wait sample code for java.lang.Object.wait() definition code for java.lang.Object.wait() , wait sample code for java.lang.Object.wait(long) definition code for java.lang.Object.wait(long) , wait sample code for java.lang.Object.wait(long, int) definition code for java.lang.Object.wait(long, int)
 

Constructor Detail

MenuItem sample code for java.awt.MenuItem() definition code for java.awt.MenuItem()

public MenuItem()
         throws HeadlessException sample code for java.awt.HeadlessException definition code for java.awt.HeadlessException 
Constructs a new MenuItem with an empty label and no keyboard shortcut.

Throws:
HeadlessException sample code for java.awt.HeadlessException definition code for java.awt.HeadlessException - if GraphicsEnvironment.isHeadless() returns true.
Since:
JDK1.1
See Also:
GraphicsEnvironment.isHeadless() sample code for java.awt.GraphicsEnvironment.isHeadless() definition code for java.awt.GraphicsEnvironment.isHeadless()

MenuItem sample code for java.awt.MenuItem(java.lang.String) definition code for java.awt.MenuItem(java.lang.String)

public MenuItem(String sample code for java.lang.String definition code for java.lang.String  label)
         throws HeadlessException sample code for java.awt.HeadlessException definition code for java.awt.HeadlessException 
Constructs a new MenuItem with the specified label and no keyboard shortcut. Note that use of "-" in a label is reserved to indicate a separator between menu items. By default, all menu items except for separators are enabled.

Parameters:
label - the label for this menu item.
Throws:
HeadlessException sample code for java.awt.HeadlessException definition code for java.awt.HeadlessException - if GraphicsEnvironment.isHeadless() returns true.
Since:
JDK1.0
See Also:
GraphicsEnvironment.isHeadless() sample code for java.awt.GraphicsEnvironment.isHeadless() definition code for java.awt.GraphicsEnvironment.isHeadless()

MenuItem sample code for java.awt.MenuItem(java.lang.String, java.awt.MenuShortcut) definition code for java.awt.MenuItem(java.lang.String, java.awt.MenuShortcut)

public MenuItem(String sample code for java.lang.String definition code for java.lang.String  label,
                MenuShortcut sample code for java.awt.MenuShortcut definition code for java.awt.MenuShortcut  s)
         throws HeadlessException sample code for java.awt.HeadlessException definition code for java.awt.HeadlessException 
Create a menu item with an associated keyboard shortcut. Note that use of "-" in a label is reserved to indicate a separator between menu items. By default, all menu items except for separators are enabled.

Parameters:
label - the label for this menu item.
s - the instance of MenuShortcut associated with this menu item.
Throws:
HeadlessException sample code for java.awt.HeadlessException definition code for java.awt.HeadlessException - if GraphicsEnvironment.isHeadless() returns true.
Since:
JDK1.1
See Also:
GraphicsEnvironment.isHeadless() sample code for java.awt.GraphicsEnvironment.isHeadless() definition code for java.awt.GraphicsEnvironment.isHeadless()
Method Detail

addNotify sample code for java.awt.MenuItem.addNotify() definition code for java.awt.MenuItem.addNotify()

public void addNotify()
Creates the menu item's peer. The peer allows us to modify the appearance of the menu item without changing its functionality.


getLabel sample code for java.awt.MenuItem.getLabel() definition code for java.awt.MenuItem.getLabel()

public String sample code for java.lang.String definition code for java.lang.String  getLabel()
Gets the label for this menu item.

Returns:
the label of this menu item, or null if this menu item has no label.
Since:
JDK1.0
See Also:
setLabel(java.lang.String) sample code for java.awt.MenuItem.setLabel(java.lang.String) definition code for java.awt.MenuItem.setLabel(java.lang.String)

setLabel sample code for java.awt.MenuItem.setLabel(java.lang.String) definition code for java.awt.MenuItem.setLabel(java.lang.String)

public void setLabel(String sample code for java.lang.String definition code for java.lang.String  label)
Sets the label for this menu item to the specified label.

Parameters:
label - the new label, or null for no label.
Since:
JDK1.0
See Also:
getLabel() sample code for java.awt.MenuItem.getLabel() definition code for java.awt.MenuItem.getLabel()

isEnabled sample code for java.awt.MenuItem.isEnabled() definition code for java.awt.MenuItem.isEnabled()

public boolean isEnabled()
Checks whether this menu item is enabled.

Since:
JDK1.0
See Also:
setEnabled(boolean) sample code for java.awt.MenuItem.setEnabled(boolean) definition code for java.awt.MenuItem.setEnabled(boolean)

setEnabled sample code for java.awt.MenuItem.setEnabled(boolean) definition code for java.awt.MenuItem.setEnabled(boolean)

public void setEnabled(boolean b)
Sets whether or not this menu item can be chosen.

Parameters:
b - if true, enables this menu item; if false, disables it.
Since:
JDK1.1
See Also:
isEnabled() sample code for java.awt.MenuItem.isEnabled() definition code for java.awt.MenuItem.isEnabled()

enable sample code for java.awt.MenuItem.enable() definition code for java.awt.MenuItem.enable()

@Deprecated
public void enable()
Deprecated. As of JDK version 1.1, replaced by setEnabled(boolean).


enable sample code for java.awt.MenuItem.enable(boolean) definition code for java.awt.MenuItem.enable(boolean)

@Deprecated
public void enable(boolean b)
Deprecated. As of JDK version 1.1, replaced by setEnabled(boolean).


disable sample code for java.awt.MenuItem.disable() definition code for java.awt.MenuItem.disable()

@Deprecated
public void disable()
Deprecated. As of JDK version 1.1, replaced by setEnabled(boolean).


getShortcut sample code for java.awt.MenuItem.getShortcut() definition code for java.awt.MenuItem.getShortcut()

public MenuShortcut sample code for java.awt.MenuShortcut definition code for java.awt.MenuShortcut  getShortcut()
Get the MenuShortcut object associated with this menu item,

Returns:
the menu shortcut associated with this menu item, or null if none has been specified.
Since:
JDK1.1
See Also:
setShortcut(java.awt.MenuShortcut) sample code for java.awt.MenuItem.setShortcut(java.awt.MenuShortcut) definition code for java.awt.MenuItem.setShortcut(java.awt.MenuShortcut)

setShortcut sample code for java.awt.MenuItem.setShortcut(java.awt.MenuShortcut) definition code for java.awt.MenuItem.setShortcut(java.awt.MenuShortcut)

public void setShortcut(MenuShortcut sample code for java.awt.MenuShortcut definition code for java.awt.MenuShortcut  s)
Set the MenuShortcut object associated with this menu item. If a menu shortcut is already associated with this menu item, it is replaced.

Parameters:
s - the menu shortcut to associate with this menu item.
Since:
JDK1.1
See Also:
getShortcut() sample code for java.awt.MenuItem.getShortcut() definition code for java.awt.MenuItem.getShortcut()

deleteShortcut sample code for java.awt.MenuItem.deleteShortcut() definition code for java.awt.MenuItem.deleteShortcut()

public void deleteShortcut()
Delete any MenuShortcut object associated with this menu item.

Since:
JDK1.1

enableEvents sample code for java.awt.MenuItem.enableEvents(long) definition code for java.awt.MenuItem.enableEvents(long)

protected final void enableEvents(long eventsToEnable)
Enables event delivery to this menu item for events to be defined by the specified event mask parameter

Since event types are automatically enabled when a listener for that type is added to the menu item, this method only needs to be invoked by subclasses of MenuItem which desire to have the specified event types delivered to processEvent regardless of whether a listener is registered.

Parameters:
eventsToEnable - the event mask defining the event types
Since:
JDK1.1
See Also:
processEvent(java.awt.AWTEvent) sample code for java.awt.MenuItem.processEvent(java.awt.AWTEvent) definition code for java.awt.MenuItem.processEvent(java.awt.AWTEvent) , disableEvents(long) sample code for java.awt.MenuItem.disableEvents(long) definition code for java.awt.MenuItem.disableEvents(long) , Component.enableEvents(long) sample code for java.awt.Component.enableEvents(long) definition code for java.awt.Component.enableEvents(long)

disableEvents sample code for java.awt.MenuItem.disableEvents(long) definition code for java.awt.MenuItem.disableEvents(long)

protected final void disableEvents(long eventsToDisable)
Disables event delivery to this menu item for events defined by the specified event mask parameter.

Parameters:
eventsToDisable - the event mask defining the event types
Since:
JDK1.1
See Also:
processEvent(java.awt.AWTEvent) sample code for java.awt.MenuItem.processEvent(java.awt.AWTEvent) definition code for java.awt.MenuItem.processEvent(java.awt.AWTEvent) , enableEvents(long) sample code for java.awt.MenuItem.enableEvents(long) definition code for java.awt.MenuItem.enableEvents(long) , Component.disableEvents(long) sample code for java.awt.Component.disableEvents(long) definition code for java.awt.Component.disableEvents(long)

setActionCommand sample code for java.awt.MenuItem.setActionCommand(java.lang.String) definition code for java.awt.MenuItem.setActionCommand(java.lang.String)

public void setActionCommand(String sample code for java.lang.String definition code for java.lang.String  command)
Sets the command name of the action event that is fired by this menu item.

By default, the action command is set to the label of the menu item.

Parameters:
command - the action command to be set for this menu item.
Since:
JDK1.1
See Also:
getActionCommand() sample code for java.awt.MenuItem.getActionCommand() definition code for java.awt.MenuItem.getActionCommand()

getActionCommand sample code for java.awt.MenuItem.getActionCommand() definition code for java.awt.MenuItem.getActionCommand()

public String sample code for java.lang.String definition code for java.lang.String  getActionCommand()
Gets the command name of the action event that is fired by this menu item.

Since:
JDK1.1
See Also:
setActionCommand(java.lang.String) sample code for java.awt.MenuItem.setActionCommand(java.lang.String) definition code for java.awt.MenuItem.setActionCommand(java.lang.String)

addActionListener sample code for java.awt.MenuItem.addActionListener(java.awt.event.ActionListener) definition code for java.awt.MenuItem.addActionListener(java.awt.event.ActionListener)

public void addActionListener(ActionListener sample code for java.awt.event.ActionListener definition code for java.awt.event.ActionListener  l)
Adds the specified action listener to receive action events from this menu item. If l is null, no exception is thrown and no action is performed.

Parameters:
l - the action listener.
Since:
JDK1.1
See Also:
removeActionListener(java.awt.event.ActionListener) sample code for java.awt.MenuItem.removeActionListener(java.awt.event.ActionListener) definition code for java.awt.MenuItem.removeActionListener(java.awt.event.ActionListener) , getActionListeners() sample code for java.awt.MenuItem.getActionListeners() definition code for java.awt.MenuItem.getActionListeners() , ActionEvent sample code for java.awt.event.ActionEvent definition code for java.awt.event.ActionEvent , ActionListener sample code for java.awt.event.ActionListener definition code for java.awt.event.ActionListener

removeActionListener sample code for java.awt.MenuItem.removeActionListener(java.awt.event.ActionListener) definition code for java.awt.MenuItem.removeActionListener(java.awt.event.ActionListener)

public void removeActionListener(ActionListener sample code for java.awt.event.ActionListener definition code for java.awt.event.ActionListener  l)
Removes the specified action listener so it no longer receives action events from this menu item. If l is null, no exception is thrown and no action is performed.

Parameters:
l - the action listener.
Since:
JDK1.1
See Also:
addActionListener(java.awt.event.ActionListener) sample code for java.awt.MenuItem.addActionListener(java.awt.event.ActionListener) definition code for java.awt.MenuItem.addActionListener(java.awt.event.ActionListener) , getActionListeners() sample code for java.awt.MenuItem.getActionListeners() definition code for java.awt.MenuItem.getActionListeners() , ActionEvent sample code for java.awt.event.ActionEvent definition code for java.awt.event.ActionEvent , ActionListener sample code for java.awt.event.ActionListener definition code for java.awt.event.ActionListener

getActionListeners sample code for java.awt.MenuItem.getActionListeners() definition code for java.awt.MenuItem.getActionListeners()

public ActionListener sample code for java.awt.event.ActionListener definition code for java.awt.event.ActionListener [] getActionListeners()
Returns an array of all the action listeners registered on this menu item.

Returns:
all of this menu item's ActionListeners or an empty array if no action listeners are currently registered
Since:
1.4
See Also:
addActionListener(java.awt.event.ActionListener) sample code for java.awt.MenuItem.addActionListener(java.awt.event.ActionListener) definition code for java.awt.MenuItem.addActionListener(java.awt.event.ActionListener) , removeActionListener(java.awt.event.ActionListener) sample code for java.awt.MenuItem.removeActionListener(java.awt.event.ActionListener) definition code for java.awt.MenuItem.removeActionListener(java.awt.event.ActionListener) , ActionEvent sample code for java.awt.event.ActionEvent definition code for java.awt.event.ActionEvent , ActionListener sample code for java.awt.event.ActionListener definition code for java.awt.event.ActionListener

getListeners sample code for java.awt.MenuItem.<T extends java.util.EventListener>getListeners(java.lang.Class<T>) definition code for java.awt.MenuItem.<T extends java.util.EventListener>getListeners(java.lang.Class<T>)

public <T extends EventListener sample code for java.util.EventListener definition code for java.util.EventListener > T[] getListeners(Class sample code for java.lang.Class definition code for java.lang.Class <T> listenerType)
Returns an array of all the objects currently registered as FooListeners upon this MenuItem. FooListeners are registered using the addFooListener method.

You can specify the listenerType argument with a class literal, such as FooListener.class. For example, you can query a MenuItem m for its action listeners with the following code:

ActionListener[] als = (ActionListener[])(m.getListeners(ActionListener.class));
If no such listeners exist, this method returns an empty array.

Parameters:
listenerType - the type of listeners requested; this parameter should specify an interface that descends from java.util.EventListener
Returns:
an array of all objects registered as FooListeners on this menu item, or an empty array if no such listeners have been added
Throws:
ClassCastException sample code for java.lang.ClassCastException definition code for java.lang.ClassCastException - if listenerType doesn't specify a class or interface that implements java.util.EventListener
Since:
1.3
See Also:
getActionListeners() sample code for java.awt.MenuItem.getActionListeners() definition code for java.awt.MenuItem.getActionListeners()

processEvent sample code for java.awt.MenuItem.processEvent(java.awt.AWTEvent) definition code for java.awt.MenuItem.processEvent(java.awt.AWTEvent)

protected void processEvent(AWTEvent sample code for java.awt.AWTEvent definition code for java.awt.AWTEvent  e)
Processes events on this menu item. If the event is an instance of ActionEvent, it invokes processActionEvent, another method defined by MenuItem.

Currently, menu items only support action events.

Note that if the event parameter is null the behavior is unspecified and may result in an exception.

Overrides:
processEvent sample code for java.awt.MenuComponent.processEvent(java.awt.AWTEvent) definition code for java.awt.MenuComponent.processEvent(java.awt.AWTEvent) in class MenuComponent sample code for java.awt.MenuComponent definition code for java.awt.MenuComponent
Parameters:
e - the event
Since:
JDK1.1
See Also:
processActionEvent(java.awt.event.ActionEvent) sample code for java.awt.MenuItem.processActionEvent(java.awt.event.ActionEvent) definition code for java.awt.MenuItem.processActionEvent(java.awt.event.ActionEvent)

processActionEvent sample code for java.awt.MenuItem.processActionEvent(java.awt.event.ActionEvent) definition code for java.awt.MenuItem.processActionEvent(java.awt.event.ActionEvent)

protected void processActionEvent(ActionEvent sample code for java.awt.event.ActionEvent definition code for java.awt.event.ActionEvent  e)
Processes action events occurring on this menu item, by dispatching them to any registered ActionListener objects. This method is not called unless action events are enabled for this component. Action events are enabled when one of the following occurs:

Note that if the event parameter is null the behavior is unspecified and may result in an exception.

Parameters:
e - the action event
Since:
JDK1.1
See Also:
ActionEvent sample code for java.awt.event.ActionEvent definition code for java.awt.event.ActionEvent , ActionListener sample code for java.awt.event.ActionListener definition code for java.awt.event.ActionListener , enableEvents(long) sample code for java.awt.MenuItem.enableEvents(long) definition code for java.awt.MenuItem.enableEvents(long)

paramString sample code for java.awt.MenuItem.paramString() definition code for java.awt.MenuItem.paramString()

public String sample code for java.lang.String definition code for java.lang.String  paramString()
Returns a string representing the state of this MenuItem. 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 null.

Overrides:
paramString sample code for java.awt.MenuComponent.paramString() definition code for java.awt.MenuComponent.paramString() in class MenuComponent sample code for java.awt.MenuComponent definition code for java.awt.MenuComponent
Returns:
the parameter string of this menu item

getAccessibleContext sample code for java.awt.MenuItem.getAccessibleContext() definition code for java.awt.MenuItem.getAccessibleContext()

public AccessibleContext sample code for javax.accessibility.AccessibleContext definition code for javax.accessibility.AccessibleContext  getAccessibleContext()
Gets the AccessibleContext associated with this MenuItem. For menu items, the AccessibleContext takes the form of an AccessibleAWTMenuItem. A new AccessibleAWTMenuItem instance is created if necessary.

Specified by:
getAccessibleContext sample code for javax.accessibility.Accessible.getAccessibleContext() definition code for javax.accessibility.Accessible.getAccessibleContext() in interface Accessible sample code for javax.accessibility.Accessible definition code for javax.accessibility.Accessible
Overrides:
getAccessibleContext sample code for java.awt.MenuComponent.getAccessibleContext() definition code for java.awt.MenuComponent.getAccessibleContext() in class MenuComponent sample code for java.awt.MenuComponent definition code for java.awt.MenuComponent
Returns:
an AccessibleAWTMenuItem that serves as the AccessibleContext of this MenuItem