当前页面:
在线文档首页 >
JDK 5 Documentation v1.1.8, Java 2 SDK 英文文档
Class java.awt.MenuItem - JDK 5 Documentation v1.1.8, Java 2 SDK 英文文档
All Packages Class Hierarchy This Package Previous Next Index
Class java.awt.MenuItem
java.lang.Object
|
+----java.awt.MenuComponent
|
+----java.awt.MenuItem
- public class MenuItem
- extends MenuComponent
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 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.
-
MenuItem()
-
Constructs a new MenuItem with an empty label and no keyboard
shortcut.
-
MenuItem(String)
-
Constructs a new MenuItem with the specified label
and no keyboard shortcut.
-
MenuItem(String, MenuShortcut)
- Create a menu item with an associated keyboard shortcut.
-
addActionListener(ActionListener)
- Adds the specified action listener to receive action events
from this menu item.
-
addNotify()
- Creates the menu item's peer.
-
deleteShortcut()
- Delete any
MenuShortcut
object associated
with this menu item.
-
disable()
-
Deprecated.
-
disableEvents(long)
- Disables event delivery to this menu item for events
defined by the specified event mask parameter.
-
enable()
-
Deprecated.
-
enable(boolean)
-
Deprecated.
-
enableEvents(long)
- 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.
-
getActionCommand()
- Gets the command name of the action event that is fired
by this menu item.
-
getLabel()
- Gets the label for this menu item.
-
getShortcut()
- Get the
MenuShortcut
object associated with this
menu item,
-
isEnabled()
- Checks whether this menu item is enabled.
-
paramString()
- Returns the parameter string representing the state of this menu
item.
-
processActionEvent(ActionEvent)
-
Processes action events occurring on this menu item,
by dispatching them to any registered
ActionListener
objects.
-
processEvent(AWTEvent)
- Processes events on this menu item.
-
removeActionListener(ActionListener)
- Removes the specified action listener so it no longer receives
action events from this menu item.
-
setActionCommand(String)
- Sets the command name of the action event that is fired
by this menu item.
-
setEnabled(boolean)
- Sets whether or not this menu item can be chosen.
-
setLabel(String)
- Sets the label for this menu item to the specified label.
-
setShortcut(MenuShortcut)
-
Set the
MenuShortcut
object associated with this
menu item.
MenuItem
public MenuItem()
- Constructs a new MenuItem with an empty label and no keyboard
shortcut.
MenuItem
public MenuItem(String label)
- 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.
MenuItem
public MenuItem(String label,
MenuShortcut s)
- 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.
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
public 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.
- See Also:
- setLabel
setLabel
public synchronized void setLabel(String label)
- Sets the label for this menu item to the specified label.
- Parameters:
- label - the new label, or
null
for no label.
- See Also:
- getLabel
isEnabled
public boolean isEnabled()
- Checks whether this menu item is enabled.
- See Also:
- setEnabled
setEnabled
public synchronized 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.
- See Also:
- isEnabled
enable
public synchronized void enable()
- Note: enable() is deprecated.
As of JDK version 1.1,
replaced by
setEnabled(boolean)
.
enable
public void enable(boolean b)
- Note: enable() is deprecated.
As of JDK version 1.1,
replaced by
setEnabled(boolean)
.
disable
public synchronized void disable()
- Note: disable() is deprecated.
As of JDK version 1.1,
replaced by
setEnabled(boolean)
.
getShortcut
public 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.
- See Also:
- setShortcut
setShortcut
public void setShortcut(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.
- See Also:
- getShortcut
deleteShortcut
public void deleteShortcut()
- Delete any
MenuShortcut
object associated
with this menu item.
enableEvents
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.
- See Also:
- processEvent, disableEvents, enableEvents
disableEvents
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.
- See Also:
- processEvent, enableEvents, disableEvents
setActionCommand
public void setActionCommand(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.
- See Also:
- getActionCommand
getActionCommand
public String getActionCommand()
- Gets the command name of the action event that is fired
by this menu item.
- See Also:
- setActionCommand
addActionListener
public synchronized void addActionListener(ActionListener l)
- Adds the specified action listener to receive action events
from this menu item.
- Parameters:
- l - the action listener.
- See Also:
- ActionEvent, ActionListener, removeActionListener
removeActionListener
public synchronized void removeActionListener(ActionListener l)
- Removes the specified action listener so it no longer receives
action events from this menu item.
- Parameters:
- l - the action listener.
- See Also:
- ActionEvent, ActionListener, addActionListener
processEvent
protected void processEvent(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.
- Parameters:
- e - the event.
- Overrides:
- processEvent in class MenuComponent
- See Also:
- processActionEvent
processActionEvent
protected void processActionEvent(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:
- An
ActionListener
object is registered
via addActionListener
.
- Action events are enabled via
enableEvents
.
- Parameters:
- e - the action event.
- See Also:
- ActionEvent, ActionListener, enableEvents
paramString
public String paramString()
- Returns the parameter string representing the state of this menu
item. This string is useful for debugging.
- Returns:
- the parameter string of this menu item.
- Overrides:
- paramString in class MenuComponent
All Packages Class Hierarchy This Package Previous Next Index
Submit a bug or feature - Version 1.1.8 of Java Platform API Specification
Java is a trademark or registered trademark of Sun Microsystems, Inc. in the US and other countries.
Copyright 1995-1999 Sun Microsystems, Inc. 901 San Antonio Road,
Palo Alto, California, 94303, U.S.A. All Rights Reserved.