Packages  This Package  Prev  Next  Index  

§1.32 Class MenuItem

public  class  java.awt.MenuItem
    extends  java.awt.MenuComponent  (II-§1.31)
{
        // Constructors
    public MenuItem(String  label);	§1.32.1

        // Methods
    public void addNotify();	§1.32.2
    public void disable();	§1.32.3
    public void enable();	§1.32.4
    public void enable(boolean  cond);	§1.32.5
    public String getLabel();	§1.32.6
    public boolean isEnabled();	§1.32.7
    public String paramString();	§1.32.8
    public void setLabel(String  label);	§1.32.9
}
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 (page II-188) shows five menu items. The first two are simple menu items labelled "Basic" and "Simple". Following it is a separator (see §1.32.1). Next is a CheckboxMenuItem (II-§1.7) labelled "Check". Finally, there is a submenu labelled "More Examples", which is an instance of Menu (II-§1.29).

When a menu item is selected, the AWT sends an action event (II-§1.14.13) 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.


Constructors

MenuItem

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.
Parameters:
label - the label for the menu item

Methods

addNotify

public void addNotify()
This method calls the createMenuItem method (II-§1.41.16) of this object's toolkit (II-§1.10.20) in order to create a MenuItemPeer (II-§3.15) 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.

disable

public void disable()
Disables this menu item. It can no longer be selected by the user.

enable

public void enable()
Enables this menu item; it can be selected by the user.

enable

public void enable(boolean cond)
Enables this menu item if the flag is true; otherwise, disables it.
Parameters:
cond - if true, enable this menu item; otherwise disable it
See Also:
enable (II-§1.32.4)
disable (II-§1.32.3).

getLabel

public String getLabel()
Returns:
the label of this menu item, or null if this menu item has no label.

isEnabled

public boolean isEnabled()
Checks whether this menu item is enabled.
Returns:
true if this menu item is enabled; false otherwise.

paramString

public String paramString()
Returns the parameter string representing the state of this menu item. This string is useful for debugging.
Returns:
the parameter string of this menu item.
Overrides:
paramString in class MenuComponent (II-§1.31.5).

setLabel

public void setLabel(String label)
Changes this menu item's label to be the label argument.
Parameters:
label - the new label, or null for no label

Packages  This Package  Prev  Next  Index
Java API Document (HTML generated by dkramer on April 22, 1996)
Copyright © 1996 Sun Microsystems, Inc. All rights reserved
Please send any comments or corrections to doug.kramer@sun.com