Java Reference
In-Depth Information
In the simple case, confining presentation objects to the event thread is completely natural.
Listing 9.3 creates a button whose color changes randomly when pressed. When the user
clicks on the button, the toolkit delivers an ActionEvent in the event thread to all re-
gistered action listeners. In response, the action listener picks a new color and changes the
button's background color. So the event originates in the GUI toolkit and is delivered to the
application, and the application modifies the GUI in response to the user's action. Control
never has to leave the event thread, as illustrated in Figure 9.1 .
Figure 9.1. Control Flow of a Simple Button Click.
This trivial example characterizes the majority of interactions between GUI applications and
GUI toolkits. So long as tasks are short-lived and access only GUI objects (or other thread-
confined or thread-safe application objects), you can almost totally ignore threading concerns
and do everything from the event thread, and the right thing happens.
Search WWH ::




Custom Search