Review of actionPerformed()

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 previous page   go to home page   go to next page

Answer:

actionPerformed()

Review of actionPerformed()

The parameter for actionPerformed() is a reference to an ActionEvent object, a subclass of AWTEvent. When a button is clicked, actionPerformed() is called with a new ActionEvent parameter. So far, we've not used the ActionEvent object. We will do this shortly. Here is the picture:

ActionEvent

The registered ActionListener may be the object that contains the button. For small applications, this is an object of a type that is a subclass of JFrame. (In other words, you define a class based on JFrame.) The class contains the button and also implements the ActionListener interface.

In larger applications, the registered listener may be in a class by itself, or be in a JPanel. See the following chapters.

QUESTION 2:

Could a frame hold two buttons?