Java Doc for MenuItem.java in  » 6.0-JDK-Core » AWT » java » awt » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Home
Java Source Code / Java Documentation
1.6.0 JDK Core
2.6.0 JDK Modules
3.6.0 JDK Modules com.sun
4.6.0 JDK Modules com.sun.java
5.6.0 JDK Modules sun
6.6.0 JDK Platform
7.Ajax
8.Apache Harmony Java SE
9.Aspect oriented
10.Authentication Authorization
11.Blogger System
12.Build
13.Byte Code
14.Cache
15.Chart
16.Chat
17.Code Analyzer
18.Collaboration
19.Content Management System
20.Database Client
21.Database DBMS
22.Database JDBC Connection Pool
23.Database ORM
24.Development
25.EJB Server
26.ERP CRM Financial
27.ESB
28.Forum
29.Game
30.GIS
31.Graphic 3D
32.Graphic Library
33.Groupware
34.HTML Parser
35.IDE
36.IDE Eclipse
37.IDE Netbeans
38.Installer
39.Internationalization Localization
40.Inversion of Control
41.Issue Tracking
42.J2EE
43.J2ME
44.JBoss
45.JMS
46.JMX
47.Library
48.Mail Clients
49.Music
50.Net
51.Parser
52.PDF
53.Portal
54.Profiler
55.Project Management
56.Report
57.RSS RDF
58.Rule Engine
59.Science
60.Scripting
61.Search Engine
62.Security
63.Sevlet Container
64.Source Control
65.Swing Library
66.Template Engine
67.Test Coverage
68.Testing
69.UML
70.Web Crawler
71.Web Framework
72.Web Mail
73.Web Server
74.Web Services
75.Web Services apache cxf 2.2.6
76.Web Services AXIS2
77.Wiki Engine
78.Workflow Engines
79.XML
80.XML UI
Java Source Code / Java Documentation » 6.0 JDK Core » AWT » java.awt 
Source Cross Reference  Class Diagram Java Document (Java Doc) 


java.lang.Object
   java.awt.MenuComponent
      java.awt.MenuItem

All known Subclasses:   java.awt.Menu,  java.awt.CheckboxMenuItem,
MenuItem
public class MenuItem extends MenuComponent implements Accessible(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 following text describes this graphic.
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.101, 05/05/07
author:
   Sami Shaio


Inner Class :protected class AccessibleAWTMenuItem extends AccessibleAWTMenuComponent implements AccessibleAction,AccessibleValue

Field Summary
 StringactionCommand
     This field indicates the command tha has been issued by a particular menu item.
transient  ActionListeneractionListener
    
 booleanenabled
     A value to indicate whether a menu item is enabled or not.
 longeventMask
     The eventMask is ONLY set by subclasses via enableEvents.
 Stringlabel
     label is the label of a menu item.

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  voidaddActionListener(ActionListener l)
     Adds the specified action listener to receive action events from this menu item.
public  voidaddNotify()
     Creates the menu item's peer.
 StringconstructComponentName()
     Construct a name for this MenuComponent.
public  voiddeleteShortcut()
     Delete any MenuShortcut object associated with this menu item.
 voiddeleteShortcut(MenuShortcut s)
    
public synchronized  voiddisable()
    
final protected  voiddisableEvents(long eventsToDisable)
     Disables event delivery to this menu item for events defined by the specified event mask parameter.
 voiddoMenuEvent(long when, int modifiers)
    
public synchronized  voidenable()
    
public  voidenable(boolean b)
    
final protected  voidenableEvents(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.

 booleaneventEnabled(AWTEvent e)
    
public  AccessibleContextgetAccessibleContext()
     Gets the AccessibleContext associated with this MenuItem.
public  StringgetActionCommand()
     Gets the command name of the action event that is fired by this menu item.
final  StringgetActionCommandImpl()
    
public synchronized  ActionListener[]getActionListeners()
     Returns an array of all the action listeners registered on this menu item.
public  StringgetLabel()
     Gets the label for this menu item.
public  T[]getListeners(Class<T> listenerType)
     Returns an array of all the objects currently registered as FooListeners upon this MenuItem.
public  MenuShortcutgetShortcut()
    
 MenuItemgetShortcutMenuItem(MenuShortcut s)
    
 booleanhandleShortcut(KeyEvent e)
    
public  booleanisEnabled()
     Checks whether this menu item is enabled.
public  StringparamString()
     Returns a string representing the state of this 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.
protected  voidprocessActionEvent(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  voidprocessEvent(AWTEvent e)
     Processes events on this menu item.
public synchronized  voidremoveActionListener(ActionListener l)
     Removes the specified action listener so it no longer receives action events from this menu item.
public  voidsetActionCommand(String command)
     Sets the command name of the action event that is fired by this menu item.
public synchronized  voidsetEnabled(boolean b)
     Sets whether or not this menu item can be chosen.
public synchronized  voidsetLabel(String label)
     Sets the label for this menu item to the specified label.
public  voidsetShortcut(MenuShortcut s)
     Set the MenuShortcut object associated with this menu item.

Field Detail
actionCommand
String actionCommand(Code)
This field indicates the command tha has been issued by a particular menu item. By default the actionCommand is the label of the menu item, unless it has been set using setActionCommand.
See Also:   MenuItem.setActionCommand(String)
See Also:   MenuItem.getActionCommand()



actionListener
transient ActionListener actionListener(Code)



enabled
boolean enabled(Code)
A value to indicate whether a menu item is enabled or not. If it is enabled, enabled will be set to true. Else enabled will be set to false.
See Also:   MenuItem.isEnabled()
See Also:   MenuItem.setEnabled(boolean)



eventMask
long eventMask(Code)
The eventMask is ONLY set by subclasses via enableEvents. The mask should NOT be set when listeners are registered so that we can distinguish the difference between when listeners request events and subclasses request them.



label
String label(Code)
label is the label of a menu item. It can be any string.
See Also:   MenuItem.getLabel()
See Also:   MenuItem.setLabel(String)




Constructor Detail
MenuItem
public MenuItem() throws HeadlessException(Code)
Constructs a new MenuItem with an empty label and no keyboard shortcut.
exception:
  HeadlessException - if GraphicsEnvironment.isHeadless()returns true.
See Also:   java.awt.GraphicsEnvironment.isHeadless
since:
   JDK1.1



MenuItem
public MenuItem(String label) throws HeadlessException(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.
exception:
  HeadlessException - if GraphicsEnvironment.isHeadless()returns true.
See Also:   java.awt.GraphicsEnvironment.isHeadless
since:
   JDK1.0



MenuItem
public MenuItem(String label, MenuShortcut s) throws HeadlessException(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 MenuShortcutassociated with this menu item.
exception:
  HeadlessException - if GraphicsEnvironment.isHeadless()returns true.
See Also:   java.awt.GraphicsEnvironment.isHeadless
since:
   JDK1.1




Method Detail
addActionListener
public synchronized void addActionListener(ActionListener l)(Code)
Adds the specified action listener to receive action events from this menu item. If l is null, no exception is thrown and no action is performed.

Refer to AWT Threading Issues for details on AWT's threading model.
Parameters:
  l - the action listener.
See Also:   MenuItem.removeActionListener
See Also:   MenuItem.getActionListeners
See Also:   java.awt.event.ActionEvent
See Also:   java.awt.event.ActionListener
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



deleteShortcut
void deleteShortcut(MenuShortcut s)(Code)



disable
public synchronized void disable()(Code)



disableEvents
final protected void disableEvents(long eventsToDisable)(Code)
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:   java.awt.MenuItem.processEvent
See Also:   java.awt.MenuItem.enableEvents
See Also:   java.awt.Component.disableEvents
since:
   JDK1.1



doMenuEvent
void doMenuEvent(long when, int modifiers)(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




eventEnabled
boolean eventEnabled(AWTEvent e)(Code)



getAccessibleContext
public AccessibleContext getAccessibleContext()(Code)
Gets the AccessibleContext associated with this MenuItem. For menu items, the AccessibleContext takes the form of an AccessibleAWTMenuItem. A new AccessibleAWTMenuItem instance is created if necessary. an AccessibleAWTMenuItem that serves as the AccessibleContext of this MenuItem
since:
   1.3



getActionCommand
public String getActionCommand()(Code)
Gets the command name of the action event that is fired by this menu item.
See Also:   java.awt.MenuItem.setActionCommand
since:
   JDK1.1



getActionCommandImpl
final String getActionCommandImpl()(Code)



getActionListeners
public synchronized ActionListener[] getActionListeners()(Code)
Returns an array of all the action listeners registered on this menu item. all of this menu item's ActionListenersor an empty array if no actionlisteners are currently registered
See Also:   MenuItem.addActionListener
See Also:   MenuItem.removeActionListener
See Also:   java.awt.event.ActionEvent
See Also:   java.awt.event.ActionListener
since:
   1.4



getLabel
public String getLabel()(Code)
Gets the label for this menu item. the label of this menu item, or nullif this menu item has no label.
See Also:   java.awt.MenuItem.setLabel
since:
   JDK1.0



getListeners
public T[] getListeners(Class<T> listenerType)(Code)
Returns an array of all the objects currently registered as FooListeners upon this MenuItem. FooListeners 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.
Parameters:
  listenerType - the type of listeners requested; this parametershould specify an interface that descends fromjava.util.EventListener an array of all objects registered asFooListeners on this menu item,or an empty array if no suchlisteners have been added
exception:
  ClassCastException - if listenerTypedoesn't specify a class or interface that implementsjava.util.EventListener
See Also:   MenuItem.getActionListeners
since:
   1.3



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



getShortcutMenuItem
MenuItem getShortcutMenuItem(MenuShortcut s)(Code)



handleShortcut
boolean handleShortcut(KeyEvent e)(Code)



isEnabled
public boolean isEnabled()(Code)
Checks whether this menu item is enabled.
See Also:   java.awt.MenuItem.setEnabled
since:
   JDK1.0



paramString
public String paramString()(Code)
Returns a string representing the state of this 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. the parameter string of this menu item



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.

Note that if the event parameter is null the behavior is unspecified and may result in an exception.
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.

Note that if the event parameter is null the behavior is unspecified and may result in an exception.
Parameters:
  e - the event
See Also:   java.awt.MenuItem.processActionEvent
since:
   JDK1.1




removeActionListener
public synchronized void removeActionListener(ActionListener l)(Code)
Removes the specified action listener so it no longer receives action events from this menu item. If l is null, no exception is thrown and no action is performed.

Refer to AWT Threading Issues for details on AWT's threading model.
Parameters:
  l - the action listener.
See Also:   MenuItem.addActionListener
See Also:   MenuItem.getActionListeners
See Also:   java.awt.event.ActionEvent
See Also:   java.awt.event.ActionListener
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



Fields inherited from java.awt.MenuComponent
AccessibleContext accessibleContext(Code)(Java Doc)
final static String actionListenerK(Code)(Java Doc)
transient AppContext appContext(Code)(Java Doc)
Font font(Code)(Java Doc)
final static String itemListenerK(Code)(Java Doc)
boolean newEventsOnly(Code)(Java Doc)
transient MenuContainer parent(Code)(Java Doc)
transient MenuComponentPeer peer(Code)(Java Doc)

Methods inherited from java.awt.MenuComponent
String constructComponentName()(Code)(Java Doc)
final public void dispatchEvent(AWTEvent e)(Code)(Java Doc)
void dispatchEventImpl(AWTEvent e)(Code)(Java Doc)
boolean eventEnabled(AWTEvent e)(Code)(Java Doc)
int getAccessibleChildIndex(MenuComponent child)(Code)(Java Doc)
public AccessibleContext getAccessibleContext()(Code)(Java Doc)
int getAccessibleIndexInParent()(Code)(Java Doc)
AccessibleStateSet getAccessibleStateSet()(Code)(Java Doc)
public Font getFont()(Code)(Java Doc)
final Font getFont_NoClientCode()(Code)(Java Doc)
public String getName()(Code)(Java Doc)
public MenuContainer getParent()(Code)(Java Doc)
final MenuContainer getParent_NoClientCode()(Code)(Java Doc)
public MenuComponentPeer getPeer()(Code)(Java Doc)
final protected Object getTreeLock()(Code)(Java Doc)
protected String paramString()(Code)(Java Doc)
public boolean postEvent(Event evt)(Code)(Java Doc)
protected void processEvent(AWTEvent e)(Code)(Java Doc)
public void removeNotify()(Code)(Java Doc)
public void setFont(Font f)(Code)(Java Doc)
public void setName(String name)(Code)(Java Doc)
public String toString()(Code)(Java Doc)

Methods inherited from java.lang.Object
native protected Object clone() throws CloneNotSupportedException(Code)(Java Doc)
public boolean equals(Object obj)(Code)(Java Doc)
protected void finalize() throws Throwable(Code)(Java Doc)
final native public Class getClass()(Code)(Java Doc)
native public int hashCode()(Code)(Java Doc)
final native public void notify()(Code)(Java Doc)
final native public void notifyAll()(Code)(Java Doc)
public String toString()(Code)(Java Doc)
final native public void wait(long timeout) throws InterruptedException(Code)(Java Doc)
final public void wait(long timeout, int nanos) throws InterruptedException(Code)(Java Doc)
final public void wait() throws InterruptedException(Code)(Java Doc)

www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.