JaVa
   

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 TemplateGraphicsapp 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 TemplateGraphicsapp class.

JaVa
   
Comments