public class EventQueue extends Object
EventQueue是平台独立的类,队列的事件,无论是从底层的对等体类和从受信任的应用程序类。
它封装了异步事件调度机械提取事件队列和调度这些调用dispatchEvent(AWTEvent)方法在此EventQueue与事件被派遣作为参数。这种机械的特殊行为是依赖于实现的。唯一的要求是事件实际上是排队队列(注意,这一事件被发布到EventQueue可以合并)派遣:
AWTEvent 一排队的
EventQueue之前
AWTEvent B然后事件B不会出动前事件A.
一些浏览器的分区程序在不同的代码库为独立的语境,这些语境的墙壁之间建立。在这样的情况下,会有每一EventQueue语境。其他浏览器将所有程序在相同的情况下,这意味着将只有一个单一的,所有应用程序的全球EventQueue。这种行为是依赖于实现的。请咨询您的浏览器的文档以了解更多信息。
在线程问题的事件调度机械信息,看到AWT Threading Issues。
| Constructor and Description |
|---|
EventQueue() |
| Modifier and Type | Method and Description |
|---|---|
SecondaryLoop |
createSecondaryLoop()
创建一个新的与此事件相关的
secondary loop队列。
|
protected void |
dispatchEvent(AWTEvent event)
调度事件。
|
static AWTEvent |
getCurrentEvent()
返回事件目前正在派出由调用线程相关的
EventQueue。
|
static long |
getMostRecentEventTime()
返回最近的事件,有一个时间戳戳,那是从调用线程相关的
EventQueue出动。
|
AWTEvent |
getNextEvent()
删除从
EventQueue事件并返回。
|
static void |
invokeAndWait(Runnable runnable)
|
static void |
invokeLater(Runnable runnable)
|
static boolean |
isDispatchThread()
如果调用线程的调度线程
the current AWT EventQueue返回true。
|
AWTEvent |
peekEvent()
返回在
EventQueue第一事件没有消除。
|
AWTEvent |
peekEvent(int id)
返回指定的身份证的第一个事件,如果有。
|
protected void |
pop()
停止使用该
EventQueue调度事件。
|
void |
postEvent(AWTEvent theEvent)
岗位1.1-style事件的
EventQueue。
|
void |
push(EventQueue newEventQueue)
用指定的替换现有的
EventQueue。
|
public void postEvent(AWTEvent theEvent)
EventQueue。如果有一个现有的事件队列中的同一个ID的事件源,源
Component的
coalesceEvents方法会被调用。
theEvent -
java.awt.AWTEvent实例,或子类,它
null
theEvent
NullPointerException
public AWTEvent getNextEvent() throws InterruptedException
EventQueue事件并返回。这种方法将阻止,直到一个事件已被另一个线程发布。
AWTEvent
InterruptedException -如果任何线程中断了这个线程
public AWTEvent peekEvent()
EventQueue第一事件没有消除。
public AWTEvent peekEvent(int id)
id -事件类型所需的ID
null第一事件,如果没有这样的事件
protected void dispatchEvent(AWTEvent event)
| Event Type | Source Type | Dispatched To |
|---|---|---|
| ActiveEvent | Any | event.dispatch() |
| Other | Component | source.dispatchEvent(AWTEvent) |
| Other | MenuComponent | source.dispatchEvent(AWTEvent) |
| Other | Other | No action (ignored) |
event -
java.awt.AWTEvent实例,或子类,它
null
event
NullPointerException
public static long getMostRecentEventTime()
EventQueue出动。如果一个时间戳的事件正在布控,将返回的时间戳。如果没有事件尚未派遣的EventQueue的初始化时间将返回。在JDK,当前版本只
InputEvents,
ActionEvents,和
InvocationEvents有时间戳;然而,JDK的未来版本可能会添加时间戳的额外的事件类型。请注意,此方法只能从一个应用程序的
event dispatching thread调用。如果此方法是从另一个线程调用,系统当前时间(据
System.currentTimeMillis())将返回。
InputEvent,
ActionEvent时间戳,或
InvocationEvent发运,或
System.currentTimeMillis()如果这种方法比其他事件调度线程的线程调用
InputEvent.getWhen(),
ActionEvent.getWhen(),
InvocationEvent.getWhen(),
isDispatchThread()
public static AWTEvent getCurrentEvent()
EventQueue。这是有用的,如果一个方法需要访问的事件,但不是设计来获得一个参考它作为一个参数。请注意,此方法只应在应用程序的事件调度线程中调用。如果此方法是从另一个线程调用的,则将返回。
public void push(EventQueue newEventQueue)
EventQueue。任何挂起的事件被转移到新的
EventQueue处理它。
newEventQueue -
EventQueue(或子类的实例是使用方法)
null
newEventQueue
NullPointerException
pop()
protected void pop()
throws EmptyStackException
EventQueue调度事件。任何挂起的事件转移到以前的
EventQueue处理。
警告:为了避免死锁,不要在子类中声明此方法。
EmptyStackException推了这
EventQueue
push(java.awt.EventQueue)
public SecondaryLoop createSecondaryLoop()
SecondaryLoop.enter(),
SecondaryLoop.exit()
public static boolean isDispatchThread()
the current AWT EventQueue返回true。使用这种方法,以确保在那里执行特定的任务(或不存在)。
注意:使用invokeLater(java.lang.Runnable)或invokeAndWait(java.lang.Runnable)方法在the current AWT EventQueue的调度线程执行任务。
the current AWT EventQueue的调度线程运行
invokeLater(java.lang.Runnable),
invokeAndWait(java.lang.Runnable),
Toolkit.getSystemEventQueue()
public static void invokeLater(Runnable runnable)
runnable的
run方法应在
the system EventQueue的
event dispatch thread异步执行的
Runnable
invokeAndWait(java.lang.Runnable),
Toolkit.getSystemEventQueue(),
isDispatchThread()
public static void invokeAndWait(Runnable runnable) throws InterruptedException, InvocationTargetException
runnable有其
run法在
the system EventQueue的
dispatch thread称,这将发生在所有待处理事件。调用块,直到发生了这样的情况。这个方法如果从
event dispatcher thread叫抛出一个错误。
runnable的
run方法应在
the system EventQueue的
event dispatch thread同步执行的
Runnable
InterruptedException -如果任何线程中断了这个线程
InvocationTargetException -如果一个Throwable抛出运行时
runnable
invokeLater(java.lang.Runnable),
Toolkit.getSystemEventQueue(),
isDispatchThread()
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.