created: 3/24/99 (using AWT);
major revision: 01/08/02 (using Swing);
revised: 02/07/04, 02/13/05, 07/17/06
CHAPTER 57 — Buttons and Actions
The previous chapters have introduced
event-driven programming
and the three parts of a GUI application:
- The Graphical User Interface:
- Container objects — JFrame
- Other objects — buttons, text fields, others.
- Listener methods:
- Each GUI object has a listener object registered for it
for each type of event it generates for which a response is
expected.
- Application code.
- The purpose of the program.
This chapter discusses how to add a button
to a frame and how to register a
listener for its events.
Chapter Topics:
- Adding a button to a frame.
- The content pane of a frame.
- Layout managers.
- Action listeners.
- Registering a listener with a GUI component.
- The
actionPerformed()
method.
- Changing the background color of a frame.