CHAPTER 59 — Buttons and Action Events

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: 6/26/99 (using AWT); revised: 01/26/00, 01/09/02 (using Swing), 07/19/06; refurbished 11/02/08

CHAPTER 59 — Buttons and Action Events

We have been doing event-driven programing. The three parts of a GUI application are:

  1. Components that make up the Graphical User Interface. <—— we've done this; this chapter will do more.
  2. Listener methods that receive the events and respond to them. <—— we've done this; this chapter will do more.
  3. Application methods that does useful work for the user. <—— we've not done this, yet.

Soon we will get to the third step, and you will actually write a full GUI application! But not yet. This chapter continues the discussion on how to add button components to a frame, and how the actionPerformed() can tell which button was clicked.

Chapter Topics:

  • A Button's setActionCommand() method.
  • An ActionEvent's getActionCommand() method.
  • Using actionPerformed() with several buttons.

QUESTION 1:

What is the name of the method that receives ActionEvents when a button is clicked?