home | O'Reilly's CD bookshelfs | FreeBSD | Linux | Cisco | Cisco Exam  


Java AWT

Previous Chapter 19
java.awt Reference
Next
 

MenuItem

Name

MenuItem

[Graphic: Figure from the text]

Description

The MenuItem class represents a selectable item on a menu.

Class Definition

public class java.awt.MenuItem
    extends java.awt.MenuComponent {
  
  // Constructors
  public MenuItem(); (New)
  public MenuItem (String label);
  public MenuItem (String label, MenuShortcut s); (New)
  
  // Instance Methods
  public void addActionListener (ActionListener l); (New)
  public void addNotify();
  public void deleteShortcut(); (New)
  public synchronized void disable(); (Deprecated)
  public synchronized void enable(); (Deprecated)
  public void enable (boolean condition); (Deprecated)
  public String getActionCommand(); (New)
  public String getLabel();
  public MenuShortcut getShortcut(); (New)
  public boolean isEnabled();
  public String paramString();
  public void removeActionListener (ActionListener l); (New)
  public void setActionCommand (String command); (New)
  public synchronized void setEnabled (boolean b); (New)
  public synchronized void setLabel (String label);
  public void setShortcut (MenuShortcut s); (New)
  // Protected Instance Methods
  protected final void disableEvents (long eventsToDisable); (New)
  protected final void enableEvents (long eventsToEnable); (New)
  protected void processActionEvent (ActionEvent e); (New)
  protected void processEvent (AWTEvent e); (New)
}

Constructors

MenuItem

public MenuItem() (New)

Description

Constructs a MenuItem object with no label or shortcut.

public MenuItem (String label)

Parameters

label

Text that appears on the MenuItem.

Description

Constructs a MenuItem object.

public MenuItem (String label, MenuShortcut s) (New)

Parameters

label

Text that appears on the MenuItem.

s

Shortcut for the MenuItem.

Description

Constructs a MenuItem object with the given shortcut.

Instance Methods

addActionListener

public void addActionListener(ActionListener l) (New)

Parameters

l

An object that implements the ActionListener interface.

Description

Add a listener for the action event.

addNotify

public void addNotify()

Description

Creates the MenuItem's peer.

deleteShortcut

public void deleteShortcut() (New)

Description

Removes the shortcut associated with this item.

disable

public synchronized void disable() (Deprecated)

Description

Disables the menu component so that it is unresponsive to user interactions. Replaced by setEnabled(false).

enable

public synchronized void enable() (Deprecated)

Description

Enables the menu component so that it is responsive to user interactions. Replaced by setEnabled(true).

public void enable (boolean condition) (Deprecated)

Parameters

condition

true to enable the menu component; false to disable it.

Description

Enables or disables the menu component, depending on the condition parameter. Replaced by setEnabled(boolean).

getActionCommand

public String getActionCommand() (New)

Returns

Current action command string.

Description

Returns the string used for the action command.

getLabel

public String getLabel()

Returns

The current text associated with the MenuItem.

getShortcut

public MenuShortcut getShortcut() (New)

Returns

The current shortcut for this item, or null if there is none.

isEnabled

public boolean isEnabled()

Returns

true if the menu item is enabled, false otherwise.

paramString

public String paramString()

Returns

String with current settings of MenuItem.

Description

Helper method for toString() to generate string of current settings.

removeActionListener

public void removeActionListener(ActionListener l) (New)

Parameters

l

One of this Button's ActionListeners.

Description

Remove an action event listener.

setActionCommand

public void setActionCommand(String command) (New)

Parameters

command

New action command string.

Description

Specify the string used for the action command.

setEnabled

public synchronized void setEnabled (boolean b) (New)

Parameters

b

true to enable the item, false to disable it.

Description

Enables or disables the item. Replaces enable(), enable(boolean), and disable().

setLabel

public synchronized void setLabel (String label)

Parameters

label

New text to appear on MenuItem.

Description

Changes the label of the MenuItem.

setShortcut

public void setShortcut (MenuShortcut s) (New)

Parameters

s

New shortcut for the MenuItem.

Description

Changes the shortcut of the MenuItem.

Protected Instance Methods

disableEvents

protected final void disableEvents (long eventsToDisable) (New)

Parameters

eventsToDisable

A value representing certain kinds of events. This can be constructed by ORing the event mask constants defined in java.awt.AWTEvent.

Description

By default, a menu item receives events corresponding to the event listeners that have registered. If a menu item should not receive events of a certain type, even if there is a listener registered for that type of event, this method can be used to disable that event type.

enableEvents

protected final void enableEvents (long eventsToEnable) (New)

Parameters

eventsToDisable

A value representing certain kinds of events. This can be constructed by ORing the event mask constants defined in java.awt.AWTEvent.

Description

By default, a menu item receives events corresponding to the event listeners that have registered. If a menu item should receive other types of events as well, this method can be used to get them.

processActionEvent

protected void processActionEvent (ActionEvent e) (New)

Parameters

e

The action event to process.

Description

Action events are passed to this method for processing. Normally, this method is called by processEvent().

processEvent

protected void processEvent (AWTEvent e) (New)

Parameters

e

The event to process.

Description

Low-level AWTEvents are passed to this method for processing.

See Also

CheckboxMenuItem, Menu, MenuComponent, MenuShortcut, String


Previous Home Next
MenuContainer Book Index MenuShortcut (New)

Java in a Nutshell Java Language Reference Java AWT Java Fundamental Classes Exploring Java