Working with the event queue

The java.awt.EventQueue class represents a queue of events waiting to be processed. You can create your own instances of this class using the norags constructor:

public EventQueue()

For example,

EventQueue MyQueue = new EventQueue();

However, most of the time you'll be more interested in the system event queue. This is created for you automatically. You can get a reference to it with the getSystemEventQueue() method in the java.awt.Toolkit class like this:

EventQueue systemQueue = Toolkit.getDefaultToolkit().getSystemEventQueue();

An applet cannot call this method without generating a security exception.

Oncee you have a reference to the system event queue, you can manipulate it with the following methods:

     public synchronized void postEvent(AWTEvent e)
     public synchronized AWTEvent getNextEvent()
     public synchronized AWTEvent peekEvent()
     public synchronized AWTEvent peekEvent(int n)
postEvent() lets you put an event in the queue. getNextEvent() removes and returns the top event in the queue. peekEvent() returns the top event in the queue but does not remove it from the queue. peekEvent(int n) returns the nth event in the queue.


Next | Previous | Top
Last Modified April 18, 1997
Copyright 1997 Elliotte Rusty Harold
elharo@sunsite.unc.edu