Program's Output

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:

Visually nothing happens. The actionPerformed() method is called with a new Event object, but it changes nothing. If you feel like some fun, modify the code so that each click changes the background color.

Program's Output

The Java system automatically paints the frame when any of several things has happened:

  • The frame has just been created.
  • The frame has been maximized.
  • The frame was previously hidden behind another frame and has just been exponsed.

However, a mere button click does not necessarily mean that a frame should be repainted. If it does, as it does in this program, call repaint() in the actionPerformed() method.

clicking a button

The pictures show the output of the program. The original frame is on the left. On the right is the frame after a button click.

QUESTION 16:

(Memory Test: ) What is the name of the method that receives ActionEvents when a button is clicked?