A good answer might be:

actionPerformed()

Not Quite Correct Program

Here is the program with an actionPerformed() method added in the correct place. You can copy this program to Notepad, compile, and run it. However, there is something wrong with it.

import java.awt.*; 
import java.awt.event.*;
import javax.swing.*; 

public class TwoButtons extends JFrame implements ActionListener
{
  JButton redButton ;
  JButton grnButton ;

  // constructor for TwoButtons
  public TwoButtons()                           
  {
    redButton = new JButton("Red");
    grnButton = new JButton("Green");
    getContentPane().setLayout( new FlowLayout() ); 
    getContentPane().add( redButton );                      
    getContentPane().add( grnButton );
    

    // register the buttonDemo frame
    // (the frame this constructor is making)
    // as the listener for both Buttons.
     
    redButton.addActionListener( this );
    grnButton.addActionListener( this );      
  }


  public void actionPerformed( ActionEvent evt)
  {
    getContentPane().setBackground( Color.blue );
    repaint();
  }
  
  public static void main ( String[] args )
  {
    TwoButtons demo  = new TwoButtons() ;
    
    WindowQuitter wquit = new WindowQuitter();  
    demo.addWindowListener( wquit );  
    
    demo.setSize( 200, 150 );     
    demo.setVisible( true );      

  }
}

class WindowQuitter extends WindowAdapter
{
  public void windowClosing( WindowEvent e )
  {
    System.exit( 0 );  
  }
}

Check back to the description of what this program is supposed to do (its specifications) and determinine where the current version of the program errors.

QUESTION 11:

What is wrong with the program?