Java Reference
In-Depth Information
Display 17.1
Event Firing and an Event Listener
The component (for
example, a button) fires an
event.
event
component
listener
This listener object invokes an event handler
method with the event as an argument.
the next thing that happens depends on the next event. It is as though the listeners are
robots that interact with other objects (possibly other robots) in response to events
(signals) from these other objects. You program the robots, but the environment and
other robots determine what any particular robot will actually end up doing.
If you have never done event-driven programming before, one aspect of it may seem
strange to you: You will be writing definitions for methods that you will never invoke in
any program. This will likely feel a bit strange at first, because a method is of no value
unless it is invoked. So, somebody or something other than you, the programmer,
must be invoking these methods. That is exactly what does happen. The Swing system
automatically invokes certain methods when an event signals that the method needs to
be called.
Event-driven programming with the Swing library makes extensive use of
inheritance. The classes you define will be derived classes of some basic Swing library
classes. These derived classes will inherit methods from their base class. For many
of these inherited methods, library software will determine when these methods are
invoked, but you will override the definition of the inherited method to determine
what will happen when the method is invoked.
17.2
Buttons, Events, and Other Swing Basics
One button click is worth a thousand key strokes.
ANONYMOUS
In this section, we present enough about Swing to allow you to do some simple GUI
programs.
 
 
Search WWH ::




Custom Search