|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--java.awt.MenuComponent | +--java.awt.MenuItem
Unsafe: 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.
Field Summary | |
(package private) String |
actionCommand
This field indicates the command tha has been issued by a particular menu item. |
(package private) ActionListener |
actionListener
|
private static String |
base
|
(package private) boolean |
enabled
A value to indicate whether a menu item is enabled or not. |
(package private) long |
eventMask
The eventMask is ONLY set by subclasses via enableEvents. |
(package private) String |
label
label is the label of a menu item. |
private int |
menuItemSerializedDataVersion
Menu item serialized data version. |
private static int |
nameCounter
|
private static long |
serialVersionUID
|
private MenuShortcut |
shortcut
A sequence of key stokes that ia associated with a menu item. |
Fields inherited from class java.awt.MenuComponent |
accessibleContext, actionListenerK, appContext, font, itemListenerK, newEventsOnly, parent, peer |
Constructor Summary | |
MenuItem()
Suppressed: Constructs a new MenuItem with an empty label and no keyboard shortcut. |
|
MenuItem(String label)
Suppressed: Constructs a new MenuItem with the specified label and no keyboard shortcut. |
|
MenuItem(String label,
MenuShortcut s)
Suppressed: Create a menu item with an associated keyboard shortcut. |
Method Summary | |
void |
addActionListener(ActionListener l)
Suppressed: Adds the specified action listener to receive action events from this menu item. |
void |
addNotify()
Suppressed: Creates the menu item's peer. |
(package private) String |
constructComponentName()
Construct a name for this MenuComponent. |
void |
deleteShortcut()
Suppressed: Delete any MenuShortcut object associated
with this menu item. |
(package private) void |
deleteShortcut(MenuShortcut s)
|
void |
disable()
Suppressed: @deprecated As of JDK version 1.1, replaced by setEnabled(boolean) . |
protected void |
disableEvents(long eventsToDisable)
Disables event delivery to this menu item for events defined by the specified event mask parameter. |
(package private) void |
doMenuEvent(long when,
int modifiers)
|
void |
enable()
Suppressed: @deprecated As of JDK version 1.1, replaced by setEnabled(boolean) . |
void |
enable(boolean b)
Suppressed: @deprecated As of JDK version 1.1, replaced by setEnabled(boolean) . |
protected void |
enableEvents(long eventsToEnable)
Enables event delivery to this menu item for events to be defined by the specified event mask parameter |
(package private) boolean |
eventEnabled(AWTEvent e)
|
AccessibleContext |
getAccessibleContext()
Suppressed: Gets the AccessibleContext associated with this MenuItem. |
String |
getActionCommand()
Suppressed: Gets the command name of the action event that is fired by this menu item. |
ActionListener[] |
getActionListeners()
Suppressed: Returns an array of all the action listeners registered on this menu item. |
String |
getLabel()
Suppressed: Gets the label for this menu item. |
EventListener[] |
getListeners(Class listenerType)
Suppressed: Returns an array of all the objects currently registered as FooListener s
upon this MenuItem . |
MenuShortcut |
getShortcut()
Suppressed: Get the MenuShortcut object associated with this
menu item, |
(package private) MenuItem |
getShortcutMenuItem(MenuShortcut s)
|
(package private) boolean |
handleShortcut(KeyEvent e)
|
private static void |
initIDs()
Initialize JNI field and method IDs |
boolean |
isEnabled()
Suppressed: Checks whether this menu item is enabled. |
String |
paramString()
Suppressed: Returns a string representing the state of this MenuItem . |
protected void |
processActionEvent(ActionEvent e)
Processes action events occurring on this menu item, by dispatching them to any registered ActionListener objects. |
protected void |
processEvent(AWTEvent e)
Processes events on this menu item. |
private void |
readObject(ObjectInputStream s)
Reads the ObjectInputStream and if it
isn't null adds a listener to receive
action events fired by the Menu Item. |
void |
removeActionListener(ActionListener l)
Suppressed: Removes the specified action listener so it no longer receives action events from this menu item. |
void |
setActionCommand(String command)
Suppressed: Sets the command name of the action event that is fired by this menu item. |
void |
setEnabled(boolean b)
Suppressed: Sets whether or not this menu item can be chosen. |
void |
setLabel(String label)
Suppressed: Sets the label for this menu item to the specified label. |
void |
setShortcut(MenuShortcut s)
Suppressed: Set the MenuShortcut object associated with this
menu item. |
private void |
writeObject(ObjectOutputStream s)
Writes default serializable fields to stream. |
Methods inherited from class java.awt.MenuComponent |
dispatchEvent, dispatchEventImpl, getAccessibleIndexInParent, getAccessibleStateSet, getFont_NoClientCode, getFont, getName, getParent_NoClientCode, getParent, getPeer, getTreeLock, postEvent, removeNotify, setFont, setName, toString |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
boolean enabled
enabled
will
be set to true. Else enabled
will
be set to false.
isEnabled()
,
setEnabled()
String label
label
is the label of a menu item.
It can be any string.
getLabel()
,
setLabel()
String actionCommand
actionCommand
is the label of the menu item, unless it has been
set using setActionCommand.
setActionCommand()
,
getActionCommand()
long eventMask
transient ActionListener actionListener
private MenuShortcut shortcut
getShortcut()
,
setShortcut()
,
deleteShortcut()
private static final String base
private static int nameCounter
private static final long serialVersionUID
private int menuItemSerializedDataVersion
Constructor Detail |
public MenuItem() throws HeadlessException
java.awt.GraphicsEnvironment#isHeadless
public MenuItem(String label) throws HeadlessException
label
- the label for this menu item.java.awt.GraphicsEnvironment#isHeadless
public MenuItem(String label, MenuShortcut s) throws HeadlessException
label
- the label for this menu item.s
- the instance of MenuShortcut
associated with this menu item.java.awt.GraphicsEnvironment#isHeadless
Method Detail |
String constructComponentName()
constructComponentName
in class MenuComponent
MenuComponent
public void addNotify()
public String getLabel()
null
if this menu item has no label.java.awt.MenuItem#setLabel
public void setLabel(String label)
label
- the new label, or null
for no label.java.awt.MenuItem#getLabel
public boolean isEnabled()
java.awt.MenuItem#setEnabled
public void setEnabled(boolean b)
b
- if true
, enables this menu item;
if false
, disables it.java.awt.MenuItem#isEnabled
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.java.awt.MenuItem#setShortcut
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.java.awt.MenuItem#getShortcut
public void deleteShortcut()
MenuShortcut
object associated
with this menu item.
void deleteShortcut(MenuShortcut s)
void doMenuEvent(long when, int modifiers)
boolean handleShortcut(KeyEvent e)
MenuItem getShortcutMenuItem(MenuShortcut s)
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 typesjava.awt.MenuItem#processEvent
,
java.awt.MenuItem#disableEvents
,
java.awt.Component#enableEvents
protected final void disableEvents(long eventsToDisable)
eventsToDisable
- the event mask defining the event typesjava.awt.MenuItem#processEvent
,
java.awt.MenuItem#enableEvents
,
java.awt.Component#disableEvents
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.java.awt.MenuItem#getActionCommand
public String getActionCommand()
java.awt.MenuItem#setActionCommand
public void addActionListener(ActionListener l)
l
- the action listener.removeActionListener(java.awt.event.ActionListener)
,
getActionListeners()
,
java.awt.event.ActionEvent
,
java.awt.event.ActionListener
public void removeActionListener(ActionListener l)
l
- the action listener.addActionListener(java.awt.event.ActionListener)
,
getActionListeners()
,
java.awt.event.ActionEvent
,
java.awt.event.ActionListener
public ActionListener[] getActionListeners()
ActionListener
s
or an empty array if no action
listeners are currently registeredaddActionListener(java.awt.event.ActionListener)
,
removeActionListener(java.awt.event.ActionListener)
,
java.awt.event.ActionEvent
,
java.awt.event.ActionListener
public EventListener[] getListeners(Class listenerType)
FooListener
s
upon this MenuItem
.
FooListener
s 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.
listenerType
- the type of listeners requested; this parameter
should specify an interface that descends from
java.util.EventListener
FooListener
s on this menu item,
or an empty array if no such
listeners have been addedgetActionListeners()
protected void processEvent(AWTEvent e)
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.
processEvent
in class MenuComponent
e
- the eventjava.awt.MenuItem#processActionEvent
boolean eventEnabled(AWTEvent e)
eventEnabled
in class MenuComponent
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
.
Note that if the event parameter is null
the behavior is unspecified and may result in an
exception.
e
- the action eventjava.awt.event.ActionEvent
,
java.awt.event.ActionListener
,
java.awt.MenuItem#enableEvents
public String paramString()
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
.
paramString
in class MenuComponent
private void writeObject(ObjectOutputStream s) throws IOException
ActionListeners
as optional data. The non-serializable listeners are
detected and no attempt is made to serialize them.
s
- the ObjectOutputStream
to write
IOException
AWTEventMulticaster.save(ObjectOutputStream, String, EventListener)
,
readObject(java.io.ObjectInputStream)
private void readObject(ObjectInputStream s) throws ClassNotFoundException, IOException, HeadlessException
ObjectInputStream
and if it
isn't null
adds a listener to receive
action events fired by the Menu
Item.
Unrecognized keys or values will be ignored.
s
- the ObjectInputStream
to read
ClassNotFoundException
IOException
HeadlessException
removeActionListener()
,
addActionListener()
,
writeObject(java.io.ObjectOutputStream)
private static void initIDs()
public AccessibleContext getAccessibleContext()
getAccessibleContext
in interface Accessible
getAccessibleContext
in class MenuComponent
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |