| |
|
| java.lang.Object java.awt.MenuComponent java.awt.MenuItem
All known Subclasses: java.awt.CheckboxMenuItem, java.awt.Menu,
MenuItem | public class MenuItem extends MenuComponent (Code) | | 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.
version: 1.50, 08/10/01 author: Sami Shaio |
Constructor Summary | |
public | MenuItem() Constructs a new MenuItem with an empty label and no keyboard
shortcut. | public | MenuItem(String label) Constructs a new MenuItem with the specified label
and no keyboard shortcut. | 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. |
Method Summary | |
public synchronized void | addActionListener(ActionListener l) Adds the specified action listener to receive action events
from this menu item. | public void | addNotify() Creates the menu item's peer. | String | constructComponentName() Construct a name for this MenuComponent. | public void | deleteShortcut() Delete any MenuShortcut object associated
with this menu item. | void | deleteShortcut(MenuShortcut s) | public synchronized void | disable() | final protected void | disableEvents(long eventsToDisable) Disables event delivery to this menu item for events
defined by the specified event mask parameter. | void | doMenuEvent() | public synchronized void | enable() | public void | enable(boolean b) | final protected 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. | boolean | eventEnabled(AWTEvent e) | public String | getActionCommand() Gets the command name of the action event that is fired
by this menu item. | public synchronized ActionListener[] | getActionListeners() Returns an array of all the action listeners
registered on this menu item. | public String | getLabel() Gets the label for this menu item. | public MenuShortcut | getShortcut() | MenuItem | getShortcutMenuItem(MenuShortcut s) | boolean | handleShortcut(KeyEvent e) | public boolean | isEnabled() Checks whether this menu item is enabled. | public String | paramString() Returns the parameter string representing the state of this menu
item. | 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. | protected void | processEvent(AWTEvent e) Processes events on this menu item. | public synchronized void | removeActionListener(ActionListener l) Removes the specified action listener so it no longer receives
action events from this menu item. | public void | setActionCommand(String command) Sets the command name of the action event that is fired
by this menu item. | public synchronized void | setEnabled(boolean b) Sets whether or not this menu item can be chosen. | public synchronized void | setLabel(String label) Sets the label for this menu item to the specified label. | public void | setShortcut(MenuShortcut s) Set the MenuShortcut object associated with this
menu item. |
eventMask | long eventMask(Code) | | |
MenuItem | public MenuItem()(Code) | | Constructs a new MenuItem with an empty label and no keyboard
shortcut.
since: JDK1.1 |
MenuItem | public MenuItem(String label)(Code) | | 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. since: JDK1.0 |
MenuItem | public MenuItem(String label, MenuShortcut s)(Code) | | 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. Parameters: s - the instance of MenuShortcut associated with this menu item. since: JDK1.1 |
addNotify | public void addNotify()(Code) | | Creates the menu item's peer. The peer allows us to modify the
appearance of the menu item without changing its functionality.
|
constructComponentName | String constructComponentName()(Code) | | Construct a name for this MenuComponent. Called by getName() when
the name is null.
|
deleteShortcut | public void deleteShortcut()(Code) | | Delete any MenuShortcut object associated
with this menu item.
since: JDK1.1 |
disable | public synchronized void disable()(Code) | | |
doMenuEvent | void doMenuEvent()(Code) | | |
enable | public synchronized void enable()(Code) | | |
enable | public void enable(boolean b)(Code) | | |
enableEvents | final protected void enableEvents(long eventsToEnable)(Code) | | 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: java.awt.MenuItem.processEvent See Also: java.awt.MenuItem.disableEvents See Also: java.awt.Component.enableEvents since: JDK1.1 |
getLabel | public String getLabel()(Code) | | Gets the label for this menu item.
the label of this menu item, or null if this menu item has no label. See Also: java.awt.MenuItem.setLabel since: JDK1.0 |
getShortcut | public MenuShortcut getShortcut()(Code) | | Get the MenuShortcut object associated with this
menu item,
the menu shortcut associated with this menu item,or null if none has been specified. See Also: java.awt.MenuItem.setShortcut since: JDK1.1 |
paramString | public String paramString()(Code) | | Returns the parameter string representing the state of this menu
item. This string is useful for debugging.
the parameter string of this menu item. since: JDK1.0 |
processActionEvent | protected void processActionEvent(ActionEvent e)(Code) | | 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: java.awt.event.ActionEvent See Also: java.awt.event.ActionListener See Also: java.awt.MenuItem.enableEvents since: JDK1.1 |
processEvent | protected void processEvent(AWTEvent e)(Code) | | 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. See Also: java.awt.MenuItem.processActionEvent since: JDK1.1 |
setActionCommand | public void setActionCommand(String command)(Code) | | 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 setfor this menu item. See Also: java.awt.MenuItem.getActionCommand since: JDK1.1 |
setEnabled | public synchronized void setEnabled(boolean b)(Code) | | Sets whether or not this menu item can be chosen.
Parameters: b - if true , enables this menu item;if false , disables it. See Also: java.awt.MenuItem.isEnabled since: JDK1.1 |
setLabel | public synchronized void setLabel(String label)(Code) | | Sets the label for this menu item to the specified label.
Parameters: label - the new label, or null for no label. See Also: java.awt.MenuItem.getLabel since: JDK1.0 |
setShortcut | public void setShortcut(MenuShortcut s)(Code) | | 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 associatewith this menu item. See Also: java.awt.MenuItem.getShortcut since: JDK1.1 |
|
|
|