Package java.awt |
![]() Previous |
![]() Java API |
![]() Index |
![]() Next |
public class java.awt.MenuItem extends java.awt.MenuComponent { // Constructors public MenuItem(String label); // Methods public void addNotify(); public void disable(); public void enable(); public void enable(boolean cond); public String getLabel(); public boolean isEnabled(); public String paramString(); public void setLabel(String label); }
All items in a menu must belong to MenuItem class or a subclass..
The default menu item represents a simple labeled menu item.
The picture of a menu bar shows five menu items. The first two are simple menu items labelled "Basic" and "Simple". Following it is a separator (see MenuItem). Next is a CheckboxMenuItem labelled "Check". Finally, there is a submenu labelled "More Examples", which is an instance of Menu .
When a menu item is selected, the AWT sends an action event to the menu item's containing frame. The event's target is the menu item, and its object is the string label of the menu item. Note that the subclass Menu overrides this behavior and does not sent any event to the frame until one of its subitems is selected.
public MenuItem(String label)Constructs a new menu item with the specified label.
The label "-" is reserved to mean a separator between menu items. By default, all menu items except for separators are enabled.
Parameter Description label the label for the menu item
public void addNotify()This method calls the createMenuItem method of this object's toolkit in order to create a MenuItemPeer for this menu item. This peer allows the application to change the look of a menu item,without changing its functionality.
Most applications do not call this method directly.
public void disable()Disables this menu item. It can no longer be selected by the user.
public void enable()Enables this menu item; it can be selected by the user.
public void enable(boolean cond)Enables this menu item if the flag is true; otherwise, disables it.
Parameter Description cond if true, enable this menu item; otherwise disable it See Also: enable disable .
public String getLabel()Return Value:
Returns the label of this menu item, or null if this menu item has no label.
public boolean isEnabled()Checks whether this menu item is enabled.
Return Value:
Returns true if this menu item is enabled; false otherwise.
public String paramString()Returns the parameter string representing the state of this menu item. This string is useful for debugging.
Return Value:
Returns the parameter string of this menu item.
Overrides:
paramString in class MenuComponent .
public void setLabel(String label)Changes this menu item's label to be the label argument.
Parameter Description label the new label, or null for no label