public class InvocationEvent extends AWTEvent implements ActiveEvent
Runnable时,在Runnable上执行run()方法的事件。
这个类可以用作ActiveEvent的ActiveEvent而不是声明一个新类并定义dispatch() 。
该课程的EventQueue通过致电invokeLater和invokeAndWait而被放置在invokeAndWait 。 客户端代码可以使用此事实为invokeLater和invokeAndWait写入替换函数,而无需在任何AWTEventListener对象中写入特殊情况代码。
如果未指定的行为将引起id任何特定的参数InvocationEvent实例不在范围从INVOCATION_FIRST到INVOCATION_LAST 。
| Modifier and Type | Field and Description |
|---|---|
protected boolean |
catchExceptions
如果dispatch()捕获Throwable并将其存储在异常实例变量中,则设置为true。
|
static int |
INVOCATION_DEFAULT
所有InvocationEvents的默认ID。
|
static int |
INVOCATION_FIRST
标记调用事件ID的范围的第一个整数ID。
|
static int |
INVOCATION_LAST
标记调用事件ID的范围的最后一个整数ID。
|
protected Object |
notifier
在Runnable.run()方法返回或抛出异常之后或事件处理完毕后,将立即调用其notifyAll()方法的(可能为空)的对象。
|
protected Runnable |
runnable
Runnable的run()方法将被调用。
|
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| Modifier | Constructor and Description |
|---|---|
protected |
InvocationEvent(Object source, int id, Runnable runnable, Object notifier, boolean catchThrowables)
构造一个
InvocationEvent ,其中指定的源和ID将在
run时执行runnable的
run方法。
|
|
InvocationEvent(Object source, Runnable runnable)
构造一个
InvocationEvent与将执行可运行的指定的源
run时调度方法。
|
|
InvocationEvent(Object source, Runnable runnable, Object notifier, boolean catchThrowables)
构造一个
InvocationEvent与将执行可运行的指定的源
run时调度方法。
|
|
InvocationEvent(Object source, Runnable runnable, Runnable listener, boolean catchThrowables)
构造具有
InvocationEvent源的InvocationEvent,它将在
run时执行runnable的
run方法。
|
| Modifier and Type | Method and Description |
|---|---|
void |
dispatch()
执行Runnable的
run()方法,并在
run()已返回或抛出异常时通知通知程序(如果有)。
|
异常 |
getException()
返回在执行Runnable的
run()方法时捕获的任何异常。
|
Throwable |
getThrowable()
返回在执行Runnable的
run()方法时捕获的任何Throwable。
|
long |
getWhen()
返回发生此事件的时间戳。
|
boolean |
isDispatched()
如果
true事件或发送时抛出任何异常,则返回true,
false返回false。
|
String |
paramString()
返回标识此事件的参数字符串。
|
getSourcepublic static final int INVOCATION_FIRST
public static final int INVOCATION_DEFAULT
public static final int INVOCATION_LAST
protected Runnable runnable
protected volatile Object notifier
isDispatched()
protected boolean catchExceptions
public InvocationEvent(Object source, Runnable runnable)
InvocationEvent源的InvocationEvent,它将在run时执行runnable的run方法。
这是一个方便的构造函数。 形式InvocationEvent(source, runnable)的调用行为完全相同的方式为InvocationEvent(source, runnable, null, false)的调用。
此方法抛出IllegalArgumentException如果source是null 。
source -该
Object发起事件
runnable -该
Runnable其
run方法将被执行
IllegalArgumentException - 如果
source为空
EventObject.getSource() ,
InvocationEvent(Object, Runnable, Object, boolean)
public InvocationEvent(Object source, Runnable runnable, Object notifier, boolean catchThrowables)
InvocationEvent源的InvocationEvent,它将在run时执行runnable的run方法。
如果通知是非null , notifyAll()将它称为后立即run返回或抛出异常。
形式InvocationEvent(source, runnable, notifier, catchThrowables)的调用行为完全相同的方式为InvocationEvent(source, InvocationEvent.INVOCATION_DEFAULT, runnable, notifier, catchThrowables)的调用。
此方法抛出IllegalArgumentException如果source是null 。
source -该
Object发起事件
runnable -
Runnable的
run方法将被执行
notifier -
Object其
notifyAll方法将在
Runnable.run后
Runnable.run已返回或抛出异常或事件被处理后
catchThrowables - 指定当执行
Runnable的
run方法时是否
dispatch应捕获Throwable,或者应该将这些Throwables传播到EventDispatchThread的调度循环
IllegalArgumentException - 如果
source为空
EventObject.getSource() ,
InvocationEvent(Object, int, Runnable, Object, boolean)
public InvocationEvent(Object source, Runnable runnable, Runnable listener, boolean catchThrowables)
InvocationEvent源的InvocationEvent ,在分派时将执行runnable的run方法。
如果听者不null , listener.run()将被调用后立即run又回来了,抛出一个异常,或者被设置在事件。
此方法抛出IllegalArgumentException如果source是null 。
source -该
Object发起事件
runnable -该
Runnable其
run方法将被执行
listener -
Runnable运行
run()方法将在
InvocationEvent之后被调用或处理
catchThrowables - 指定执行
Runnable的
run方法时是否
dispatch应该捕获Throwable,或者应该将这些Throwables传播到EventDispatchThread的调度循环
IllegalArgumentException - 如果
source为空
protected InvocationEvent(Object source, int id, Runnable runnable, Object notifier, boolean catchThrowables)
InvocationEvent源和ID的InvocationEvent ,在分派时将执行runnable的run方法。
如果通知是非null , notifyAll将它称为后立即run返回或抛出异常。
此方法抛出IllegalArgumentException如果source是null 。
source -该
Object发起事件
id - 指示事件类型的整数。
有关允许值的信息,请参阅InvocationEvent的类说明
runnable -该
Runnable其
run方法将被执行
notifier -
Object其
notifyAll方法将在
Runnable.run之后被调用返回或抛出异常或事件被处理之后
catchThrowables - 指定在执行
Runnable的
run方法时是否
dispatch应该捕获Throwable,或者应该将这些Throwables传播到EventDispatchThread的调度循环
IllegalArgumentException - 如果
source为空
EventObject.getSource() ,
AWTEvent.getID()
public void dispatch()
run()方法,并在
run()返回或引发异常时通知通知程序(如果有)。
dispatch在界面
ActiveEvent
isDispatched()
public 异常 getException()
run()方法时捕获的任何异常。
public Throwable getThrowable()
run()方法时捕获的任何Throwable。
public long getWhen()
public boolean isDispatched()
true事件或调度时抛出任何异常,返回true, false返回false。
该方法应该被调用notifier.wait()方法的等待线程调用。
由于虚假唤醒是可能的(如Object.wait()中所述 ),该方法应该在等待循环中使用,以确保事件被分派:
while (!event.isDispatched()) {
notifier.wait();
}
如果等待线程在不调度事件的情况下唤醒,则isDispatched()方法返回false ,并且while循环再次执行,从而导致唤醒的线程恢复到等待模式。
如果notifier.notifyAll()发生在等待线程进入notifier.wait()方法之前, while循环确保等待线程不会进入notifier.wait()方法。 否则,不能保证等待线程从等待中醒来。
true如果事件已经调度,或者调度时抛出任何异常,
false false
dispatch() ,
notifier ,
catchExceptions
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.