public class ActionEvent extends AWTEvent
Button)当组件特定的动作(比如被按下)。事件传递到每一个
ActionListener对象注册到使用组件的
addActionListener方法接收这样的事件。
注:调用ActionEvent在Button使用键盘,使用空格键。
实现ActionListener接口获取这ActionEvent事件发生时的对象。因此,听者不遗余力地处理单个鼠标的动作和鼠标点击的细节,并可以代替过程中一个“有意义的”(语义)的事件,如“按钮按下”。
未指定的行为将如果任何特定的ActionEvent实例的id参数不在ACTION_FIRST到ACTION_LAST范围造成的。
ActionListener,
Tutorial: How to Write an Action Listener,
Serialized Form
| Modifier and Type | Field and Description |
|---|---|
static int |
ACTION_FIRST
用于操作事件的入侵检测系统范围内的第一个数字。
|
static int |
ACTION_LAST
用于操作事件的入侵检测系统范围内的最后一个数字。
|
static int |
ACTION_PERFORMED
此事件标识表示发生了一个有意义的动作。
|
static int |
ALT_MASK
ALT改性剂。
|
static int |
CTRL_MASK
控制改性剂。
|
static int |
META_MASK
元修饰语。
|
static int |
SHIFT_MASK
移位修饰语。
|
ACTION_EVENT_MASK, ADJUSTMENT_EVENT_MASK, COMPONENT_EVENT_MASK, consumed, CONTAINER_EVENT_MASK, FOCUS_EVENT_MASK, HIERARCHY_BOUNDS_EVENT_MASK, HIERARCHY_EVENT_MASK, id, INPUT_METHOD_EVENT_MASK, INVOCATION_EVENT_MASK, ITEM_EVENT_MASK, KEY_EVENT_MASK, MOUSE_EVENT_MASK, MOUSE_MOTION_EVENT_MASK, MOUSE_WHEEL_EVENT_MASK, PAINT_EVENT_MASK, RESERVED_ID_MAX, TEXT_EVENT_MASK, WINDOW_EVENT_MASK, WINDOW_FOCUS_EVENT_MASK, WINDOW_STATE_EVENT_MASKsource| Constructor and Description |
|---|
ActionEvent(Object source, int id, String command)
构建了一个
ActionEvent对象。
|
ActionEvent(Object source, int id, String command, int modifiers)
构造一个修饰键
ActionEvent对象。
|
ActionEvent(Object source, int id, String command, long when, int modifiers)
构建与指定的组合键和时间戳的
ActionEvent对象。
|
| Modifier and Type | Method and Description |
|---|---|
String |
getActionCommand()
返回与此操作关联的命令字符串。
|
int |
getModifiers()
返回在此操作事件中按住的修改键键。
|
long |
getWhen()
返回的时间戳,这件事发生的时候。
|
String |
paramString()
返回一个确定此操作事件的参数字符串。
|
getSourcepublic static final int SHIFT_MASK
public static final int CTRL_MASK
public static final int META_MASK
public static final int ALT_MASK
public static final int ACTION_FIRST
public static final int ACTION_LAST
@Native public static final int ACTION_PERFORMED
public ActionEvent(Object source, int id, String command)
ActionEvent对象。
该方法抛出一个IllegalArgumentException如果source是null。一个null command字符串是合法的,但不推荐。
source -对象产生的事件
id -一个标识事件的整数。在允许值的信息,看到
ActionEvent类的描述
command -一个字符串,可以指定一个命令(可能是几个)与事件相关的
IllegalArgumentException -如果
source是空的
EventObject.getSource(),
AWTEvent.getID(),
getActionCommand()
public ActionEvent(Object source, int id, String command, int modifiers)
ActionEvent对象。
该方法抛出一个IllegalArgumentException如果source是null。一null command字符串是合法的,但不推荐。
source -对象产生的事件
id -一个标识事件的整数。在允许值的信息,看到
ActionEvent类的描述
command -一个字符串,可以指定一个命令(可能是几个)与事件相关的
modifiers的修饰键在事件(Shift、Ctrl、Alt、元)。不建议通过负参数。零值意味着没有通过的修饰语
IllegalArgumentException -如果
source是空的
EventObject.getSource(),
AWTEvent.getID(),
getActionCommand(),
getModifiers()
public ActionEvent(Object source, int id, String command, long when, int modifiers)
ActionEvent对象。
该方法抛出一个IllegalArgumentException如果source是null。一个null command字符串是合法的,但不推荐。
source -对象产生的事件
id -一个标识事件的整数。在允许值的信息,看到
ActionEvent类的描述
command -一个字符串,可以指定一个命令(可能是几个)与事件相关的
modifiers的修饰键在事件(Shift、Ctrl、Alt、元)。不建议通过负参数。零值意味着没有通过的修饰语
when -长出时间发生的事件。不建议通过负或零值
IllegalArgumentException -如果
source是空的
EventObject.getSource(),
AWTEvent.getID(),
getActionCommand(),
getModifiers(),
getWhen()
public String getActionCommand()
注意,如果一个null命令字符串传递给构造函数这ActionEvent,此方法返回null。
public long getWhen()
public int getModifiers()
public String paramString()
paramString 方法重写,继承类
AWTEvent
Submit a bug or feature
For further API reference and developer documentation, see Java SE Documentation. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples.
Copyright © 1993, 2014, Oracle and/or its affiliates. All rights reserved.