Java Reference
In-Depth Information
CHAPTER
13
GUI Components and
Event Handling
Now that you can create a nice-looking GUI for your programs, you are prob-
ably anxious to get started on this chapter, especially because your GUI pro-
grams from the last chapter do not have any functionality beyond looking
good. In this chapter, I will discuss the delegation model, the architecture
behind event handling in Java. We will then look at the various components of
the AWT and Swing APIs, discussing how to create them and how to handle
their events.
The Delegation Model
Events in Java are fired and handled using a design known as the delegation
model. With the delegation model, a source generates an event and a listener
handles it, creating an object-oriented approach to handling events. (A class is
written to handle the events of a component.) There are three major players in
the delegation model:
The source of the event. In GUI programming, the component is the
source of the event. Events are Java objects that are instantiated by the
component and passed as an argument to any listeners.
405
Search WWH ::




Custom Search