20. The java.awt.event Package
Contents:
This package defines classes and interfaces used for event handling in the AWT. This package, and all of its classes and interfaces, are new in Java 1.1. The members of this package fall into three categories:
Figure 20.1 shows the class hierarchy for this package. See Chapter 7, Events, for more information on events and event handling. 20.1 java.awt.event.ActionEvent (JDK 1.1)An object of this class represents a high-level "action" event generated by an AWT component. Instead of representing a direct user event, such as a mouse or keyboard event, ActionEvent represents some sort of action performed by the user on an AWT component. The getID() method returns the type of action that has occurred. For AWT-generated action events, this type is always ActionEvent.ACTION_PERFORMED; custom components can generate action events of other types. The getActionCommand() method returns a String that serves as a kind of name for the action that the event represents. The Button and MenuItem components have a setActionCommand() method that allows the programmer to specify an "action command" string to be included with any action events generated by those components. It is this value that is returned by the getActionCommand() method. When more than one Button or other component notifies the same ActionListener, you can use getActionCommand() to help determine the appropriate response to the event. This is generally a better technique than using the source object returned by getSource(). If no action command string is explicitly set, getActionCommand returns the label of the Button or MenuItem. Note, however, that internationalized programs should not rely on these labels to be constant. Finally, getModifiers() returns a value that indicates what keyboard modifiers were in effect when the action event was triggered. Use the various _MASK constants, along with the & operator to decode this value.
public class ActionEvent extends AWTEvent { // Public Constructors public ActionEvent(Object source, int id, String command); public ActionEvent(Object source, int id, String command, int modifiers); // Constants public static final int ACTION_FIRST; public static final int ACTION_LAST; public static final int ACTION_PERFORMED; public static final int ALT_MASK; public static final int CTRL_MASK; public static final int META_MASK; public static final int SHIFT_MASK; // Public Instance Methods public String getActionCommand(); public int getModifiers(); public String paramString(); // Overrides AWTEvent } Hierarchy:Object->EventObject(Serializable)->AWTEvent->ActionEvent Passed To:ActionListener.actionPerformed(), AWTEventMulticaster.actionPerformed(), Button.processActionEvent(), List.processActionEvent(), MenuItem.processActionEvent(), TextField.processActionEvent() |
|