CHAPTER 58 — Adding Buttons to a Frame
The previous chapters have introduced
event-driven programing
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 button components
to a frame and how to register a
listener for button events.
Chapter Topics:
- Adding buttons to a frame.
- Layout managers.
- Action listeners.
- Registering a listener with a GUI component.
- Changing the background color of a frame.
actionPerformed()
method
- Using
actionPerformed()
with several buttons.