Button) when
the component-specific action occurs (such as being pressed).
The event is passed to every ActionListener object
that registered to receive such events using the component's
addActionListener method.Note
To invoke an ActionEvent on a
Button using the keyboard, use the Space bar.
The object that implements the ActionListener interface
gets this ActionEvent when the event occurs. The listener
is therefore spared the details of processing individual mouse movements
and mouse clicks, and can instead process a "meaningful" (semantic)
event like "button pressed".
An unspecified behavior will be caused if the id parameter
of any particular ActionEvent instance is not
in the range from ACTION_FIRST to ACTION_LAST.
ActionListener, Tutorial: How to Write an Action Listener
| Modifier and Type | Field and Description |
|---|---|
| public static final int | ACTION_FIRST
The first number in the range of ids used for action events. |
| public static final int | ACTION_LAST
The last number in the range of ids used for action events. |
| public static final int | ACTION_PERFORMED
This event id indicates that a meaningful action occurred. |
| pack-priv String | actionCommand
The nonlocalized string that gives more details of what actually caused the event. |
| public static final int | ALT_MASK
The alt modifier. |
| public static final int | CTRL_MASK
The control modifier. |
| public static final int | META_MASK
The meta modifier. |
| pack-priv int | modifiers
This represents the key modifier that was selected, and is used to determine the state of the selected key. |
| private static final long | serialVersionUID
Use serialVersionUID from JDK 1.1 for interoperability.
|
| public static final int | SHIFT_MASK
The shift modifier. |
| pack-priv long | when
Timestamp of when this event occurred. |
| Access | Constructor and Description |
|---|---|
| public | ActionEvent(Object
The object that originated the event source, int An integer that identifies the event.
For information on allowable values, see
the class description for id, String ActionEventA string that may specify a command (possibly one
of several) associated with the event command)Constructs an |
| public | ActionEvent(Object
The object that originated the event source, int An integer that identifies the event.
For information on allowable values, see
the class description for id, String ActionEventA string that may specify a command (possibly one
of several) associated with the event command, int The modifier keys down during event
(shift, ctrl, alt, meta).
Passing negative parameter is not recommended.
Zero value means that no modifiers were passed modifiers)Constructs an |
| public | ActionEvent(Object
The object that originated the event source, int An integer that identifies the event.
For information on allowable values, see
the class description for id, String ActionEventA string that may specify a command (possibly one
of several) associated with the event command, long A long that gives the time the event occurred.
Passing negative or zero value
is not recommended when, int The modifier keys down during event
(shift, ctrl, alt, meta).
Passing negative parameter is not recommended.
Zero value means that no modifiers were passed modifiers)Constructs an |
| Modifier and Type | Method and Description |
|---|---|
| public String | Returns: the string identifying the command for this eventReturns the command string associated with this action. |
| public int | Returns: the bitwise-or of the modifier constantsReturns the modifier keys held down during this action event. |
| public long | |
| public String | Returns: a string identifying the event and its associated commandOverrides java. Returns a parameter string identifying this action event. |
| ACTION_FIRST | back to summary |
|---|---|
| public static final int ACTION_FIRST The first number in the range of ids used for action events. | |
| ACTION_LAST | back to summary |
|---|---|
| public static final int ACTION_LAST The last number in the range of ids used for action events. | |
| ACTION_PERFORMED | back to summary |
|---|---|
| public static final int ACTION_PERFORMED This event id indicates that a meaningful action occurred. | |
| actionCommand | back to summary |
|---|---|
| pack-priv String actionCommand The nonlocalized string that gives more details of what actually caused the event. This information is very specific to the component that fired it.
| |
| ALT_MASK | back to summary |
|---|---|
| public static final int ALT_MASK The alt modifier. An indicator that the alt key was held down during the event. | |
| CTRL_MASK | back to summary |
|---|---|
| public static final int CTRL_MASK The control modifier. An indicator that the control key was held down during the event. | |
| META_MASK | back to summary |
|---|---|
| public static final int META_MASK The meta modifier. An indicator that the meta key was held down during the event. | |
| modifiers | back to summary |
|---|---|
| pack-priv int modifiers This represents the key modifier that was selected, and is used to determine the state of the selected key. If no modifier has been selected it will default to zero.
| |
| serialVersionUID | back to summary |
|---|---|
| private static final long serialVersionUID Hides java. Use serialVersionUID from JDK 1.1 for interoperability. | |
| SHIFT_MASK | back to summary |
|---|---|
| public static final int SHIFT_MASK The shift modifier. An indicator that the shift key was held down during the event. | |
| when | back to summary |
|---|---|
| pack-priv long when Timestamp of when this event occurred. Because an ActionEvent is a high- level, semantic event, the timestamp is typically the same as an underlying InputEvent.
| |
| ActionEvent | back to summary |
|---|---|
| public ActionEvent(Object source, int id, String command) Constructs an
This method throws an
| |
| ActionEvent | back to summary |
|---|---|
| public ActionEvent(Object source, int id, String command, int modifiers) Constructs an
This method throws an
| |
| ActionEvent | back to summary |
|---|---|
| public ActionEvent(Object source, int id, String command, long when, int modifiers) Constructs an
This method throws an
| |
| getActionCommand | back to summary |
|---|---|
| public String getActionCommand() Returns the command string associated with this action. This string allows a "modal" component to specify one of several commands, depending on its state. For example, a single button might toggle between "show details" and "hide details". The source object and the event would be the same in each case, but the command string would identify the intended action.
Note that if a
| |
| getModifiers | back to summary |
|---|---|
| public int getModifiers() Returns the modifier keys held down during this action event.
| |
| getWhen | back to summary |
|---|---|
| public long getWhen() Returns the timestamp of when this event occurred. Because an ActionEvent is a high-level, semantic event, the timestamp is typically the same as an underlying InputEvent.
| |
| paramString | back to summary |
|---|---|
| public String paramString() Overrides java. Returns a parameter string identifying this action event. This method is useful for event-logging and for debugging.
| |