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.*;

public class TwoButtons extends Frame implements ActionListener
{
  Button redButton = new Button("Red");
  Button grnButton = new Button("Green");

  TwoButtons()                            // constructor for TwoButtons
  {  
     setLayout( new FlowLayout() );       // choose the layout manager
     redButton.addActionListener( this ); // register the buttonDemo object
     grnButton.addActionListener( this ); // as the listener
                                          // for both Buttons.
     add( redButton );                      
     add( grnButton );                      
  }

  public void actionPerformed( ActionEvent evt)
  {
    setBackground( Color.blue );
    repaint();                           // ask the system to paint the screen.
  }

  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 );  // what to do for this event--exit the program
  }
}

Check back to the 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?

Click Here after you have answered the question