public class EventQueue extends Object
EventQueue是一个独立于平台的类,用于从底层对等类和可信应用程序类排队事件。 
        它封装了从队列中提取事件,并通过调用调度它们异步事件指派机制dispatchEvent(AWTEvent)这种方法EventQueue与该事件被分派作为参数。 这种机器的特殊行为是依赖于实现的。 唯一的要求是实际排队到这个队列的事件(注意,发布到EventQueue事件可以合并)被调度: 
AWTEvent A在AWTEvent B之前排队到EventQueue ,则事件B将不会在事件A之前调度。 
         一些浏览器将不同代码库中的小程序分割成单独的上下文,并在这些上下文之间建立墙壁。 在这种情况下,每个上下文将有一个EventQueue 。 其他浏览器将所有小程序放置在相同的上下文中,这意味着所有applet将只有一个全局EventQueue 。 这种行为是依赖于实现的。 有关更多信息,请参阅浏览器的文档。 
有关事件调度机制的线程问题的信息,请参见AWT Threading Issues 。
| Constructor and Description | 
|---|
| EventQueue() | 
| Modifier and Type | Method and Description | 
|---|---|
| SecondaryLoop | createSecondaryLoop()
              创建与此事件队列 
              secondary loop联的新的secondary loop。 | 
| protected void | dispatchEvent(AWTEvent event)
              调度事件。 
             | 
| static AWTEvent | getCurrentEvent()
              返回与调用线程 
              EventQueue联的EventQueue当前调度的事件。 | 
| static long | getMostRecentEventTime()
              返回具有时间戳的最新事件的时间戳,并从与调用线程 
              EventQueue联的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)
              返回具有指定ID的第一个事件(如果有)。 
             | 
| protected void | pop()
              使用此 
              EventQueue停止调度事件。 | 
| void | postEvent(AWTEvent theEvent)
              发布一个1.1风格的事件到 
              EventQueue。 | 
| void | push(EventQueue newEventQueue)
              替换现有 
              EventQueue与指定的一个。 | 
public void postEvent(AWTEvent theEvent)
EventQueue 。 
           如果具有相同ID和事件源的队列上存在现有事件,则将调用源Component的coalesceEvents方法。 
          theEvent -实例 
            java.awt.AWTEvent ,或它的子类 
           NullPointerException - 如果 
            theEvent是 
            null 
           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 -实例 
            java.awt.AWTEvent ,或它的子类 
           NullPointerException - 如果 
            event是 
            null 
           public static long getMostRecentEventTime()
EventQueue联的EventQueue分派。 
           如果当前正在调度具有时间戳的事件,则会返回其时间戳。 
           如果没有发送任何事件,则将返回EventQueue的初始化时间。在当前版本的JDK中,只有InputEvent s, ActionEvent s和InvocationEvent具有时间戳; 
           然而,JDK的未来版本可能会向其他事件类型添加时间戳。 
           请注意,此方法只能从应用程序的event dispatching thread调用。 
           如果从另一个线程调用此方法,则将返回当前系统时间(由System.currentTimeMillis()报告)。 
          InputEvent , 
            ActionEvent ,或 
            InvocationEvent被分派,或 
            System.currentTimeMillis()如果该方法在不同于事件指派线程的线程上调用 
           InputEvent.getWhen() , 
            ActionEvent.getWhen() , 
            InvocationEvent.getWhen() , 
            isDispatchThread() 
           public static AWTEvent getCurrentEvent()
EventQueue联的EventQueue当前调度的事件。 
           如果一个方法需要对该事件的访问,但是这个方法没有被设计为接受对它的引用作为参数,这是有用的。 
           请注意,此方法只能从应用程序的事件调度线程调用。 
           如果从另一个线程调用此方法,则返回null。 
          public void push(EventQueue newEventQueue)
EventQueue与指定的一个。 
           任何待处理的事件都将传输到新的EventQueue进行处理。 
          newEventQueue - 要使用的 
            EventQueue (或其子类)实例 
           NullPointerException - 如果 
            newEventQueue是 
            null 
           pop() 
           protected void pop()
            throws EmptyStackException 
          EventQueue 。 
           任何待处理的事件都将转移到先前的EventQueue进行处理。 
           警告:为避免死锁,请勿在子类中声明此方法同步。
EmptyStackException - 如果以前没有推出这个 
            EventQueue 
           push(java.awt.EventQueue) 
           public SecondaryLoop createSecondaryLoop()
secondary loop联的新的secondary loop 。 
           使用SecondaryLoop.enter()和SecondaryLoop.exit()方法来启动和停止事件循环并从此队列调度事件。 
          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的发送线程中运行, 
            则为 true 
           invokeLater(java.lang.Runnable) , 
            invokeAndWait(java.lang.Runnable) , 
            Toolkit.getSystemEventQueue() 
           public static void invokeLater(Runnable runnable)
runnable的run方法在dispatch thread的the system EventQueue中被调用。 
           这将在所有待处理的事件被处理之后发生。 
          runnable - 
            Runnable其 
            run方法应该在88380062184298的 
            event dispatch thread中 
            异步执行 
           invokeAndWait(java.lang.Runnable) , 
            Toolkit.getSystemEventQueue() , 
            isDispatchThread() 
           public static void invokeAndWait(Runnable runnable) throws InterruptedException, InvocationTargetException
runnable在dispatch thread的dispatch thread中调用其run方法。 
           这将在所有待处理的事件被处理之后发生。 
           调用块直到发生这种情况。 
           如果从event dispatcher thread调用,此方法将抛出错误。 
          runnable - 
            Runnable其 
            run方法应在 
            event dispatch thread the system EventQueue中 
            同步执行 
           InterruptedException - 如果有任何线程已经中断了这个线程 
           InvocationTargetException - 如果在运行 
            runnable时抛出一个 
            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.