Blanks filled In

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:

The blanks are filled in below:

Blanks filled In

class ButtonFrame extends JFrame implements ActionListener
{
  JButton bChange ;

  // constructor   
  public ButtonFrame(String title) 
  {
    super( title );
    setLayout( new FlowLayout() );  

    bChange = new JButton("Click Me!"); 
    add( bChange ); 
    setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );    
  }
   
  // listener method required by the interface
  public void actionPerformed( ActionEvent evt)
  {
     . . . . . .
  }
}

In this style of GUI programming, one object (the ButtonFrame object) is playing two roles: it is the container object that holds a GUI component, and it is also the listener object for that component.

Implementing ActionListener is not enough. The listener must still be registered with the JButton.

QUESTION 12:

(Review: ) What does registering a listener do?