java.lang.Object
java.awt.MenuComponent
java.awt.MenuItem
protected class
MenuItem()
MenuItem
with no label
and no shortcut.
MenuItem(String label, MenuShortcut shortcut)
MenuItem
with the specified
label and shortcut.
void
addActionListener(ActionListener listener)
void
addNotify()
void
deleteShortcut()
void
disable()
setEnabled()
.protected void
disableEvents(long events)
void
enable()
setEnabled()
. void
enable(boolean enabled)
setEnabled()
.protected void
enableEvents(long events)
extends EventListener> T[] getListeners(Class listenerType)
- Returns all registered EventListers of the given listenerType.
AccessibleContext
getAccessibleContext()
MenuItem
.
String
getActionCommand()
MenuShortcut
getShortcut()
null
.
boolean
isEnabled()
String
paramString()
protected void
processActionEvent(ActionEvent event)
protected void
processEvent(AWTEvent event)
processActionEvent()
if it is an instance of ActionEvent
.
void
void
setActionCommand(String actionCommand)
void
setEnabled(boolean enabled)
void
setShortcut(MenuShortcut shortcut)
public MenuItem(String label)
Initializes a new instance ofMenuItem
with the specified label and no shortcut.
- Parameters:
label
- The label for this menu item.
public MenuItem(String label, MenuShortcut shortcut)
Initializes a new instance ofMenuItem
with the specified label and shortcut.
- Parameters:
label
- The label for this menu item.shortcut
- The shortcut for this menu item.
public void addActionListener(ActionListener listener)
Adds the specified listener to the list of registered action listeners for this component.
- Parameters:
listener
- The listener to add.
public void deleteShortcut()
Deletes the shortcut for this menu item if one exists. This must be done before the native peer is created.
public void disable()
Deprecated. This method is deprecated in favor of
setEnabled()
.Disables this menu item.
protected final void disableEvents(long events)
Disables the specified events.
- Parameters:
events
- The events to enable, which should be the bit masks fromAWTEvent
.
public void enable()
Deprecated. This method is deprecated in favor of
setEnabled()
.Enables this menu item.
public void enable(boolean enabled)
Deprecated. This method is deprecated in favor of
setEnabled()
.Sets the enabled status of this menu item.
- Parameters:
enabled
-true
to enable this menu item,false
otherwise.
protected final void enableEvents(long events)
Enables the specified events. This is done automatically when a listener is added and does not normally need to be done by application code.
- Parameters:
events
- The events to enable, which should be the bit masks fromAWTEvent
.
publicextends EventListener> T[] getListeners(Class listenerType)
Returns all registered EventListers of the given listenerType. listenerType must be a subclass of EventListener, or a ClassClassException is thrown.
- Since:
- 1.3
public AccessibleContext getAccessibleContext()
Gets the AccessibleContext associated with thisMenuItem
. The context is created, if necessary.
- Specified by:
- getAccessibleContext in interface Accessible
- Overrides:
- getAccessibleContext in interface MenuComponent
- Returns:
- the associated context
public String getActionCommand()
Returns the name of the action command in the action events generated by this menu item.
- Returns:
- The action command name
public ActionListener[] getActionListeners()
public String getLabel()
Returns the label for this menu item, which may benull
.
- Returns:
- The label for this menu item.
public MenuShortcut getShortcut()
Returns the shortcut for this menu item, which may benull
.
- Returns:
- The shortcut for this menu item.
public boolean isEnabled()
Tests whether or not this menu item is enabled.
- Returns:
true
if this menu item is enabled,false
otherwise.
public String paramString()
Returns a debugging string for this object.
- Overrides:
- paramString in interface MenuComponent
- Returns:
- A debugging string for this object.
protected void processActionEvent(ActionEvent event)
Processes the specified event by dispatching it to any registered listeners.
- Parameters:
event
- The event to process.
protected void processEvent(AWTEvent event)
Processes the specified event by callingprocessActionEvent()
if it is an instance ofActionEvent
.
- Overrides:
- processEvent in interface MenuComponent
- Parameters:
event
- The event to process.
public void removeActionListener(ActionListener l)
public void setActionCommand(String actionCommand)
Sets the name of the action command in the action events generated by this menu item.
- Parameters:
actionCommand
- The new action command name.
public void setEnabled(boolean enabled)
Sets the enabled status of this menu item.
- Parameters:
enabled
-true
to enable this menu item,false
otherwise.
public void setLabel(String label)
This method sets the label for this menu to the specified value.
- Parameters:
label
- The new label for this menu item.
public void setShortcut(MenuShortcut shortcut)
Sets the shortcut for this menu item to the specified value. This must be done before the native peer is created.
- Parameters:
shortcut
- The new shortcut for this menu item.