java.awt
Class EventQueue

java.lang.Object sample code for java.lang.Object definition code for java.lang.Object 
  extended by java.awt.EventQueue

public class EventQueue
extends Object sample code for java.lang.Object definition code for java.lang.Object

EventQueue is a platform-independent class that queues events, both from the underlying peer classes and from trusted application classes.

It encapsulates asynchronous event dispatch machinery which extracts events from the queue and dispatches them by calling dispatchEvent(AWTEvent) sample code for java.awt.EventQueue.dispatchEvent(java.awt.AWTEvent) definition code for java.awt.EventQueue.dispatchEvent(java.awt.AWTEvent) method on this EventQueue with the event to be dispatched as an argument. The particular behavior of this machinery is implementation-dependent. The only requirements are that events which were actually enqueued to this queue (note that events being posted to the EventQueue can be coalesced) are dispatched:

Sequentially.
That is, it is not permitted that several events from this queue are dispatched simultaneously.
In the same order as they are enqueued.
That is, if AWTEvent A is enqueued to the EventQueue before AWTEvent B then event B will not be dispatched before event A.

Some browsers partition applets in different code bases into separate contexts, and establish walls between these contexts. In such a scenario, there will be one EventQueue per context. Other browsers place all applets into the same context, implying that there will be only a single, global EventQueue for all applets. This behavior is implementation-dependent. Consult your browser's documentation for more information.

For information on the threading issues of the event dispatch machinery, see AWT Threading Issues.

Since:
1.1

Constructor Summary
EventQueue sample code for java.awt.EventQueue.EventQueue() definition code for java.awt.EventQueue.EventQueue() ()
           
 
Method Summary
protected  void dispatchEvent sample code for java.awt.EventQueue.dispatchEvent(java.awt.AWTEvent) definition code for java.awt.EventQueue.dispatchEvent(java.awt.AWTEvent) (AWTEvent sample code for java.awt.AWTEvent definition code for java.awt.AWTEvent  event)
          Dispatches an event.
static AWTEvent sample code for java.awt.AWTEvent definition code for java.awt.AWTEvent getCurrentEvent sample code for java.awt.EventQueue.getCurrentEvent() definition code for java.awt.EventQueue.getCurrentEvent() ()
          Returns the the event currently being dispatched by the EventQueue associated with the calling thread.
static long getMostRecentEventTime sample code for java.awt.EventQueue.getMostRecentEventTime() definition code for java.awt.EventQueue.getMostRecentEventTime() ()
          Returns the timestamp of the most recent event that had a timestamp, and that was dispatched from the EventQueue associated with the calling thread.
 AWTEvent sample code for java.awt.AWTEvent definition code for java.awt.AWTEvent getNextEvent sample code for java.awt.EventQueue.getNextEvent() definition code for java.awt.EventQueue.getNextEvent() ()
          Removes an event from the EventQueue and returns it.
static void invokeAndWait sample code for java.awt.EventQueue.invokeAndWait(java.lang.Runnable) definition code for java.awt.EventQueue.invokeAndWait(java.lang.Runnable) (Runnable sample code for java.lang.Runnable definition code for java.lang.Runnable  runnable)
          Causes runnable to have its run method called in the dispatch thread of the EventQueue.
static void invokeLater sample code for java.awt.EventQueue.invokeLater(java.lang.Runnable) definition code for java.awt.EventQueue.invokeLater(java.lang.Runnable) (Runnable sample code for java.lang.Runnable definition code for java.lang.Runnable  runnable)
          Causes runnable to have its run method called in the dispatch thread of the EventQueue.
static boolean isDispatchThread sample code for java.awt.EventQueue.isDispatchThread() definition code for java.awt.EventQueue.isDispatchThread() ()
          Returns true if the calling thread is the current AWT EventQueue's dispatch thread.
 AWTEvent sample code for java.awt.AWTEvent definition code for java.awt.AWTEvent peekEvent sample code for java.awt.EventQueue.peekEvent() definition code for java.awt.EventQueue.peekEvent() ()
          Returns the first event on the EventQueue without removing it.
 AWTEvent sample code for java.awt.AWTEvent definition code for java.awt.AWTEvent peekEvent sample code for java.awt.EventQueue.peekEvent(int) definition code for java.awt.EventQueue.peekEvent(int) (int id)
          Returns the first event with the specified id, if any.
protected  void pop sample code for java.awt.EventQueue.pop() definition code for java.awt.EventQueue.pop() ()
          Stops dispatching events using this EventQueue.
 void postEvent sample code for java.awt.EventQueue.postEvent(java.awt.AWTEvent) definition code for java.awt.EventQueue.postEvent(java.awt.AWTEvent) (AWTEvent sample code for java.awt.AWTEvent definition code for java.awt.AWTEvent  theEvent)
          Posts a 1.1-style event to the EventQueue.
 void push sample code for java.awt.EventQueue.push(java.awt.EventQueue) definition code for java.awt.EventQueue.push(java.awt.EventQueue) (EventQueue sample code for java.awt.EventQueue definition code for java.awt.EventQueue  newEventQueue)
          Replaces the existing EventQueue with the specified one.
 
Methods inherited from class java.lang.Object sample code for java.lang.Object definition code for java.lang.Object
clone sample code for java.lang.Object.clone() definition code for java.lang.Object.clone() , equals sample code for java.lang.Object.equals(java.lang.Object) definition code for java.lang.Object.equals(java.lang.Object) , finalize sample code for java.lang.Object.finalize() definition code for java.lang.Object.finalize() , getClass sample code for java.lang.Object.getClass() definition code for java.lang.Object.getClass() , hashCode sample code for java.lang.Object.hashCode() definition code for java.lang.Object.hashCode() , notify sample code for java.lang.Object.notify() definition code for java.lang.Object.notify() , notifyAll sample code for java.lang.Object.notifyAll() definition code for java.lang.Object.notifyAll() , toString sample code for java.lang.Object.toString() definition code for java.lang.Object.toString() , wait sample code for java.lang.Object.wait() definition code for java.lang.Object.wait() , wait sample code for java.lang.Object.wait(long) definition code for java.lang.Object.wait(long) , wait sample code for java.lang.Object.wait(long, int) definition code for java.lang.Object.wait(long, int)
 

Constructor Detail

EventQueue sample code for java.awt.EventQueue() definition code for java.awt.EventQueue()

public EventQueue()
Method Detail

postEvent sample code for java.awt.EventQueue.postEvent(java.awt.AWTEvent) definition code for java.awt.EventQueue.postEvent(java.awt.AWTEvent)

public void postEvent(AWTEvent sample code for java.awt.AWTEvent definition code for java.awt.AWTEvent  theEvent)
Posts 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
Throws:
NullPointerException sample code for java.lang.NullPointerException definition code for java.lang.NullPointerException - if theEvent is null

getNextEvent sample code for java.awt.EventQueue.getNextEvent() definition code for java.awt.EventQueue.getNextEvent()

public AWTEvent sample code for java.awt.AWTEvent definition code for java.awt.AWTEvent  getNextEvent()
                      throws InterruptedException sample code for java.lang.InterruptedException definition code for java.lang.InterruptedException 
Removes an event from the EventQueue and returns it. This method will block until an event has been posted by another thread.

Returns:
the next AWTEvent
Throws:
InterruptedException sample code for java.lang.InterruptedException definition code for java.lang.InterruptedException - if another thread has interrupted this thread

peekEvent sample code for java.awt.EventQueue.peekEvent() definition code for java.awt.EventQueue.peekEvent()

public AWTEvent sample code for java.awt.AWTEvent definition code for java.awt.AWTEvent  peekEvent()
Returns the first event on the EventQueue without removing it.

Returns:
the first event

peekEvent sample code for java.awt.EventQueue.peekEvent(int) definition code for java.awt.EventQueue.peekEvent(int)

public AWTEvent sample code for java.awt.AWTEvent definition code for java.awt.AWTEvent  peekEvent(int id)
Returns 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 or null if there is no such event

dispatchEvent sample code for java.awt.EventQueue.dispatchEvent(java.awt.AWTEvent) definition code for java.awt.EventQueue.dispatchEvent(java.awt.AWTEvent)

protected void dispatchEvent(AWTEvent sample code for java.awt.AWTEvent definition code for java.awt.AWTEvent  event)
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:

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:
event - an instance of java.awt.AWTEvent, or a subclass of it
Throws:
NullPointerException sample code for java.lang.NullPointerException definition code for java.lang.NullPointerException - if event is null

getMostRecentEventTime sample code for java.awt.EventQueue.getMostRecentEventTime() definition code for java.awt.EventQueue.getMostRecentEventTime()

public static long getMostRecentEventTime()
Returns the timestamp of the most recent event that had a timestamp, and that was dispatched from the EventQueue associated with the calling thread. If an event with a timestamp is currently being dispatched, its timestamp will be returned. If no events have yet been dispatched, the EventQueue's initialization time will be returned instead.In the current version of the JDK, only InputEvents, ActionEvents, and InvocationEvents have timestamps; however, future versions of the JDK may add timestamps to additional event types. Note that this method should only be invoked from an application's event dispatching thread. If this method is invoked from another thread, the current system time (as reported by System.currentTimeMillis()) will be returned instead.

Returns:
the timestamp of the last InputEvent, ActionEvent, or InvocationEvent to be dispatched, or System.currentTimeMillis() if this method is invoked on a thread other than an event dispatching thread
Since:
1.4
See Also:
InputEvent.getWhen() sample code for java.awt.event.InputEvent.getWhen() definition code for java.awt.event.InputEvent.getWhen() , ActionEvent.getWhen() sample code for java.awt.event.ActionEvent.getWhen() definition code for java.awt.event.ActionEvent.getWhen() , InvocationEvent.getWhen() sample code for java.awt.event.InvocationEvent.getWhen() definition code for java.awt.event.InvocationEvent.getWhen()

getCurrentEvent sample code for java.awt.EventQueue.getCurrentEvent() definition code for java.awt.EventQueue.getCurrentEvent()

public static AWTEvent sample code for java.awt.AWTEvent definition code for java.awt.AWTEvent  getCurrentEvent()
Returns the the event currently being dispatched by the EventQueue associated with the calling thread. This is useful if a method needs access to the event, but was not designed to receive a reference to it as an argument. Note that this method should only be invoked from an application's event dispatching thread. If this method is invoked from another thread, null will be returned.

Returns:
the event currently being dispatched, or null if this method is invoked on a thread other than an event dispatching thread
Since:
1.4

push sample code for java.awt.EventQueue.push(java.awt.EventQueue) definition code for java.awt.EventQueue.push(java.awt.EventQueue)

public void push(EventQueue sample code for java.awt.EventQueue definition code for java.awt.EventQueue  newEventQueue)
Replaces the existing EventQueue with the specified one. Any pending events are transferred to the new EventQueue for processing by it.

Parameters:
newEventQueue - an EventQueue (or subclass thereof) instance to be use
Throws:
NullPointerException sample code for java.lang.NullPointerException definition code for java.lang.NullPointerException - if newEventQueue is null
See Also:
pop() sample code for java.awt.EventQueue.pop() definition code for java.awt.EventQueue.pop()

pop sample code for java.awt.EventQueue.pop() definition code for java.awt.EventQueue.pop()

protected void pop()
            throws EmptyStackException sample code for java.util.EmptyStackException definition code for java.util.EmptyStackException 
Stops dispatching events using this EventQueue. Any pending events are transferred to the previous EventQueue for processing.

Warning: To avoid deadlock, do not declare this method synchronized in a subclass.

Throws:
EmptyStackException sample code for java.util.EmptyStackException definition code for java.util.EmptyStackException - if no previous push was made on this EventQueue
See Also:
push(java.awt.EventQueue) sample code for java.awt.EventQueue.push(java.awt.EventQueue) definition code for java.awt.EventQueue.push(java.awt.EventQueue)

isDispatchThread sample code for java.awt.EventQueue.isDispatchThread() definition code for 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 sample code for java.awt.EventQueue.invokeLater(java.lang.Runnable) definition code for java.awt.EventQueue.invokeLater(java.lang.Runnable)

public static void invokeLater(Runnable sample code for java.lang.Runnable definition code for java.lang.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:
1.2
See Also:
invokeAndWait(java.lang.Runnable) sample code for java.awt.EventQueue.invokeAndWait(java.lang.Runnable) definition code for java.awt.EventQueue.invokeAndWait(java.lang.Runnable)

invokeAndWait sample code for java.awt.EventQueue.invokeAndWait(java.lang.Runnable) definition code for java.awt.EventQueue.invokeAndWait(java.lang.Runnable)

public static void invokeAndWait(Runnable sample code for java.lang.Runnable definition code for java.lang.Runnable  runnable)
                          throws InterruptedException sample code for java.lang.InterruptedException definition code for java.lang.InterruptedException ,
                                 InvocationTargetException sample code for java.lang.reflect.InvocationTargetException definition code for java.lang.reflect.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 sample code for java.lang.InterruptedException definition code for java.lang.InterruptedException - if another thread has interrupted this thread
InvocationTargetException sample code for java.lang.reflect.InvocationTargetException definition code for java.lang.reflect.InvocationTargetException - if an throwable is thrown when running runnable
Since:
1.2
See Also:
invokeLater(java.lang.Runnable) sample code for java.awt.EventQueue.invokeLater(java.lang.Runnable) definition code for java.awt.EventQueue.invokeLater(java.lang.Runnable)