java.awt

Class EventQueue

public class EventQueue extends Object

This class manages a queue of AWTEvent objects that are posted to it. The AWT system uses only one event queue for all events.
Constructor Summary
EventQueue()
Initializes a new instance of EventQueue.
Method Summary
protected voiddispatchEvent(AWTEvent evt)
Dispatches an event.
static AWTEventgetCurrentEvent()
Return the event currently being dispatched by the event dispatch thread.
static longgetMostRecentEventTime()
Returns the timestamp of the most recent event that had a timestamp, or the initialization time of the event queue if no events have been fired.
AWTEventgetNextEvent()
Returns the next event in the queue.
static voidinvokeAndWait(Runnable runnable)
Causes runnable to have its run method called in the dispatch thread of the EventQueue.
static voidinvokeLater(Runnable runnable)
This arranges for runnable to have its run method called in the dispatch thread of the EventQueue.
static booleanisDispatchThread()
Return true if the current thread is the current AWT event dispatch thread.
AWTEventpeekEvent()
Returns the next event in the queue without removing it from the queue.
AWTEventpeekEvent(int id)
Returns the next event in the queue that has the specified id without removing it from the queue.
protected voidpop()
Transfer any pending events from this queue back to the parent queue that was previously push()ed.
voidpostEvent(AWTEvent evt)
Posts a new event to the queue.
voidpush(EventQueue newEventQueue)
Allows a custom EventQueue implementation to replace this one.

Constructor Detail

EventQueue

public EventQueue()
Initializes a new instance of EventQueue.

Method Detail

dispatchEvent

protected void dispatchEvent(AWTEvent evt)
Dispatches 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.

Throws: NullPointerException If event is null.

getCurrentEvent

public static AWTEvent getCurrentEvent()
Return the event currently being dispatched by the event dispatch thread. If the current thread is not the event dispatch thread, this method returns null.

Since: 1.4

getMostRecentEventTime

public static long getMostRecentEventTime()
Returns the timestamp of the most recent event that had a timestamp, or the initialization time of the event queue if no events have been fired. At present, only InputEvents, ActionEvents, InputMethodEvents, and InvocationEvents have timestamps, but this may be added to other events in future versions. If this is called by the event dispatching thread, it can be any (sequential) value, but to other threads, the safest bet is to return System.currentTimeMillis().

Returns: the most recent timestamp

Since: 1.4

See Also: getWhen getWhen getWhen getWhen

getNextEvent

public AWTEvent getNextEvent()
Returns the next event in the queue. This method will block until an event is available or until the thread is interrupted.

Returns: The next event in the queue.

Throws: InterruptedException If this thread is interrupted while waiting for an event to be posted to the queue.

invokeAndWait

public static void invokeAndWait(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. The call blocks until this has happened. This method will throw an Error if called from the event dispatcher thread.

Throws: InterruptedException If another thread has interrupted this thread. InvocationTargetException If an exception is thrown when running runnable.

Since: 1.2

invokeLater

public static void invokeLater(Runnable runnable)
This arranges for runnable to have its run method called in the dispatch thread of the EventQueue. This will happen after all pending events are processed.

Since: 1.2

isDispatchThread

public static boolean isDispatchThread()
Return true if the current thread is the current AWT event dispatch thread.

peekEvent

public AWTEvent peekEvent()
Returns the next event in the queue without removing it from the queue. This method will block until an event is available or until the thread is interrupted.

Returns: The next event in the queue.

UNKNOWN: Does not block. Returns null if there are no events on the queue.

peekEvent

public AWTEvent peekEvent(int id)
Returns the next event in the queue that has the specified id without removing it from the queue. This method will block until an event is available or until the thread is interrupted.

Parameters: id The event id to return.

Returns: The next event in the queue.

UNKNOWN: Does not block. Returns null if there are no matching events on the queue.

pop

protected void pop()
Transfer any pending events from this queue back to the parent queue that was previously push()ed. Event dispatch from this queue is suspended.

Throws: EmptyStackException If no previous push was made on this EventQueue.

postEvent

public void postEvent(AWTEvent evt)
Posts a new event to the queue.

Parameters: evt The event to post to the queue.

Throws: NullPointerException If event is null.

push

public void push(EventQueue newEventQueue)
Allows a custom EventQueue implementation to replace this one. All pending events are transferred to the new queue. Calls to postEvent, getNextEvent, and peekEvent and others are forwarded to the pushed queue until it is removed with a pop().

Throws: NullPointerException if newEventQueue is null.