Introducing the Event Dispatch Thread

The Event Dispatch Thread is a thread that is part of Java's AWT library and is also known as the AWT thread. Its purpose is to poll the system event queue, listening for events associated with your GUI (graphical user interface), such as the JFrame we are currently setting up. Examples of such events are mouse and keyboard events, button click events, and repaint requests. When an event occurs, it is added to an event queue ready for the Event Dispatch Thread to handle. This event is then handled by invoking the appropriate method or methods provided to handle the event.

Going back to our TemplateGraphicsApplication class, the paint method is invoked whenever a paint refresh request is made for the window and is handled by the Event Dispatch Thread in this way. So when would a repaint be requested on our window? Repaint events can be requested on our window both directly (by the programmer) or indirectly (such as when the user resizes the window at run time or drags another window over our window). In both instances, our window will need to be repainted by a repaint event being queued, which the Event Dispatch Thread will handle, finishing with a call to our paint method.

We will look at this in much more depth in the very important "Rendering" section of this chapter a little later. For now, we will continue building our TemplateGraphicsApplication class.



Java 1.4 Game Programming
Java 1.4 Game Programming (Wordware Game and Graphics Library)
ISBN: 1556229631
EAN: 2147483647
Year: 2003
Pages: 237

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net