java.awt
Class Menu

java.lang.Object
  |
  +--java.awt.MenuComponent
        |
        +--java.awt.MenuItem
              |
              +--java.awt.Menu
All Implemented Interfaces:
MenuContainer

public class Menu
extends MenuItem
implements MenuContainer

A Menu that is a component of a menu bar.


Constructor Summary
Menu(String label)
          Constructs a new Menu with the specified label.
Menu(String label, boolean tearOff)
          Constructs a new Menu with the specified label.
 
Method Summary
 MenuItem add(MenuItem mi)
          Adds the specified item to this menu.
 void add(String label)
          Adds an item with with the specified label to this menu.
 void addNotify()
          Creates the menu's peer.
 void addSeparator()
          Adds a separator line, or a hypen, to the menu at the current position.
 int countItems()
          Returns the number of elements in this menu.
 MenuItem getItem(int index)
          Returns the item located at the specified index of this menu.
 boolean isTearOff()
          Returns true if this is a tear-off menu.
 void remove(int index)
          Deletes the item from this menu at the specified index.
 void remove(MenuComponent item)
          Deletes the specified item from this menu.
 void removeNotify()
          Removes the menu's peer.
 
Methods inherited from class java.awt.MenuItem
disable, enable, enable, getLabel, isEnabled, paramString, setLabel
 
Methods inherited from class java.awt.MenuComponent
getFont, getParent, getPeer, postEvent, setFont, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.awt.MenuContainer
getFont, postEvent
 

Constructor Detail

Menu

public Menu(String label)
Constructs a new Menu with the specified label. This menu can not be torn off - the menu will still appear on screen after the the mouse button has been released.

Parameters:
label - the label to be added to this menu

Menu

public Menu(String label,
            boolean tearOff)
Constructs a new Menu with the specified label. If tearOff is true, the menu can be torn off - the menu will still appear on screen after the the mouse button has been released.

Parameters:
label - the label to be added to this menu
tearOff - the boolean indicating whether or not the menu will be able to be torn off.
Method Detail

addNotify

public void addNotify()
Creates the menu's peer. The peer allows us to modify the appearance of the menu without changing its functionality.

Overrides:
addNotify in class MenuItem

removeNotify

public void removeNotify()
Removes the menu's peer. The peer allows us to modify the appearance of the menu without changing its functionality.

Overrides:
removeNotify in class MenuComponent

isTearOff

public boolean isTearOff()
Returns true if this is a tear-off menu.


countItems

public int countItems()
Returns the number of elements in this menu.


getItem

public MenuItem getItem(int index)
Returns the item located at the specified index of this menu.

Parameters:
index - the position of the item to be returned

add

public MenuItem add(MenuItem mi)
Adds the specified item to this menu.

Parameters:
mi - the item to be added

add

public void add(String label)
Adds an item with with the specified label to this menu.

Parameters:
label - the text on the item

addSeparator

public void addSeparator()
Adds a separator line, or a hypen, to the menu at the current position.


remove

public void remove(int index)
Deletes the item from this menu at the specified index.

Parameters:
index - the position of the item to be removed

remove

public void remove(MenuComponent item)
Deletes the specified item from this menu.

Specified by:
remove in interface MenuContainer
Parameters:
item - the item to be removed from the menu