| Contents | Package | Class | Tree | Deprecated | Index | Help | Java 1.2 Beta 3 | ||
| PREV | NEXT | SHOW LISTS | HIDE LISTS | ||
java.lang.Object
|
+----java.awt.MenuComponent
|
+----java.awt.MenuItem
MenuItem
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.
| Constructor Summary | |
| MenuItem()
|
|
| MenuItem(String label)
|
|
| MenuItem(String label,
MenuShortcut s)
|
|
| Method Summary | |
| void | addActionListener(ActionListener l)
|
| void | addNotify()
|
| void | deleteShortcut()
MenuShortcut object associated
with this menu item.
|
| void | disable()
|
| void | disableEvents(long eventsToDisable)
|
| void | enable()
|
| void | enable(boolean b)
|
| void | enableEvents(long eventsToEnable)
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 |
| String | getActionCommand()
|
| String | getLabel()
|
| MenuShortcut | getShortcut()
MenuShortcut object associated with this
menu item,
|
| boolean | isEnabled()
|
| String | paramString()
|
| void | processActionEvent(ActionEvent e)
ActionListener objects.
|
| void | processEvent(AWTEvent e)
|
| void | removeActionListener(ActionListener l)
|
| void | setActionCommand(String command)
|
| void | setEnabled(boolean b)
|
| void | setLabel(String label)
|
| void | setShortcut(MenuShortcut s)
MenuShortcut object associated with this
menu item.
|
| Methods inherited from class java.awt.MenuComponent |
| dispatchEvent, getFont, getName, getParent, getPeer, paramString, postEvent, processEvent, removeNotify, setFont, setName, toString |
| Methods inherited from class java.lang.Object |
| clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
public MenuItem()
public MenuItem(String label)
label
- the label for this menu item.
public MenuItem(String label,
MenuShortcut s)
label
- the label for this menu item.
s
- the instance of MenuShortcut
associated with this menu item.
| Method Detail |
public void addNotify()
public String getLabel()
null
if this menu item has no label.public void setLabel(String label)
label
- the new label, or null for no label.
public boolean isEnabled()
public void setEnabled(boolean b)
b
- if true, enables this menu item;
if false, disables it.
public void enable()
setEnabled(boolean).
public void enable(boolean b)
setEnabled(boolean).
public void disable()
setEnabled(boolean).
public MenuShortcut getShortcut()
MenuShortcut object associated with this
menu item,null if none has been specified.public void setShortcut(MenuShortcut s)
MenuShortcut object associated with this
menu item. If a menu shortcut is already associated with
this menu item, it is replaced.
s
- the menu shortcut to associate
with this menu item.
public void deleteShortcut()
MenuShortcut object associated
with this menu item.protected final void enableEvents(long eventsToEnable)
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.
eventsToEnable
- the event mask defining the event types.
protected final void disableEvents(long eventsToDisable)
eventsToDisable
- the event mask defining the event types.
public void setActionCommand(String command)
By default, the action command is set to the label of the menu item.
command
- the action command to be set
for this menu item.
public String getActionCommand()
public void addActionListener(ActionListener l)
l
- the action listener.
public void removeActionListener(ActionListener l)
l
- the action listener.
protected void processEvent(AWTEvent e)
ActionEvent, it invokes
processActionEvent, another method
defined by MenuItem.
Currently, menu items only support action events.
e
- the event.
protected void processActionEvent(ActionEvent e)
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:
ActionListener object is registered
via addActionListener.
enableEvents.
e
- the action event.
public String paramString()
| Contents | Package | Class | Tree | Deprecated | Index | Help | Java 1.2 Beta 3 | ||
| PREV | NEXT | SHOW LISTS | HIDE LISTS | ||