CHAPTER 57 — Buttons and Actions

Classic programmed-learning exercises, refreshed for modern Java and presented in the current MrStyner.com portfolio style.

Modern Java noteThis archive has been refreshed for Java 25 LTS. Core language concepts remain useful, while outdated setup instructions and browser-era Java are labeled or replaced. Java 26 is the current feature release; Java 25 is used here as the stable teaching baseline.
go to home page   go to next page

created: 3/24/99 (using AWT); major revision: 01/08/02 (using Swing); revised: 02/07/04, 02/13/05, 07/17/06; refurbished: 11/01/08

CHAPTER 57 — Buttons and Actions

This chapter discusses how to add a JButton to a frame and how to register a listener for its events.

Chapter Topics:

  • Adding a button to a frame
  • Layout managers
  • Action listeners
  • Registering a listener with a GUI component
  • The actionPerformed() method
  • The content pane of a frame
  • Changing the background color of a frame

QUESTION 1:

(Review: ) What is the name of the Swing class that defines buttons?