Java Platform 1.2

java.awt
Class EventQueue

java.lang.Object
  |
  +--java.awt.EventQueue

public class EventQueue
extends Object

EventQueue is a platform-independent class that queues events, both from the underlying peer classes and from trusted application classes. There is only one EventQueue for each AppContext.


Constructor Summary
EventQueue()
           
 
Method Summary
protected  void dispatchEvent(AWTEvent event)
          Dispatch an event.
 AWTEvent getNextEvent()
          Remove an event from the queue and return it.
static void invokeAndWait(Runnable runnable)
          Causes runnable to have its run() method called in the dispatch thread of the EventQueue.
static void invokeLater(Runnable runnable)
          Causes runnable to have its run() method called in the dispatch thread of the EventQueue.
static boolean isDispatchThread()
          Returns true if the calling thread is the current AWT EventQueue's dispatch thread.
 AWTEvent peekEvent()
          Return the first event without removing it.
 AWTEvent peekEvent(int id)
          Return the first event with the specified id, if any.
protected  void pop()
          Stop dispatching events using this EventQueue instance.
 void postEvent(AWTEvent theEvent)
          Post a 1.1-style event to the EventQueue.
 void push(EventQueue newEventQueue)
          Replace the existing EventQueue with the specified one.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

EventQueue

public EventQueue()
Method Detail

postEvent

public void postEvent(AWTEvent theEvent)
Post a 1.1-style event to the EventQueue. If there is an existing event on the queue with the same ID and event source, the source component's coalesceEvents method will be called.
Parameters:
theEvent - an instance of java.awt.AWTEvent, or a subclass of it.

getNextEvent

public AWTEvent getNextEvent()
                      throws InterruptedException
Remove an event from the queue and return it. This method will block until an event has been posted by another thread.
Returns:
the next AWTEvent
Throws:
InterruptedException - if another thread has interrupted this thread.

peekEvent

public AWTEvent peekEvent()
Return the first event without removing it.
Returns:
the first event

peekEvent

public AWTEvent peekEvent(int id)
Return the first event with the specified id, if any.
Parameters:
id - the id of the type of event desired.
Returns:
the first event of the specified id

dispatchEvent

protected void dispatchEvent(AWTEvent event)
Dispatch an event. The manner in which the event is dispatched depends upon the type of the event and the type of the event's source object:

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)

Parameters:
theEvent - an instance of java.awt.AWTEvent, or a subclass of it.

push

public void push(EventQueue newEventQueue)
Replace the existing EventQueue with the specified one. Any pending events are transferred to the new EventQueue for processing by it.
Parameters:
an - EventQueue (or subclass thereof) instance to be used.
See Also:
pop()

pop

protected void pop()
            throws EmptyStackException
Stop dispatching events using this EventQueue instance. Any pending events are transferred to the previous EventQueue for processing by it.
Throws:
if - no previous push was made on this EventQueue.
See Also:
push(java.awt.EventQueue)

isDispatchThread

public static boolean isDispatchThread()
Returns true if the calling thread is the current AWT EventQueue's dispatch thread. Use this call the ensure that a given task is being executed (or not being) on the current AWT EventDispatchThread.
Returns:
true if running on the current AWT EventQueue's dispatch thread.

invokeLater

public static void invokeLater(Runnable runnable)
Causes runnable to have its run() method called in the dispatch thread of the EventQueue. This will happen after all pending events are processed.
Parameters:
runnable - the Runnable whose run() method should be executed synchronously on the EventQueue
Since:
JDK1.2
See Also:
invokeAndWait(java.lang.Runnable)

invokeAndWait

public static void invokeAndWait(Runnable runnable)
                          throws InterruptedException,
                                 InvocationTargetException
Causes runnable to have its run() method called in the dispatch thread of the EventQueue. This will happen after all pending events are processed. The call blocks until this has happened. This method will throw an Error if called from the event dispatcher thread.
Parameters:
runnable - the Runnable whose run() method should be executed synchronously on the EventQueue
Throws:
InterruptedException - if another thread has interrupted this thread
InvocationTargetException - if an exception is thrown when running runnable
Since:
JDK1.2
See Also:
invokeLater(java.lang.Runnable)

Java Platform 1.2

Submit a bug or feature Version 1.2 of Java Platform API Specification
Java is a trademark or registered trademark of Sun Microsystems, Inc. in the US and other countries.
Copyright 1993-1998 Sun Microsystems, Inc. 901 San Antonio Road,
Palo Alto, California, 94303, U.S.A. All Rights Reserved.