Answer:

See below.

Layout

The constructor is needed so that the TwoButtons object can be set up when it is constructed. The add() method is used to put GUI components into the container.

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().add( redButton );                      
    getContentPane().add( grnButton );                      

    setDefaultCloseOperation( WindowConstants.EXIT_ON_CLOSE );   
  }
  
  . . . . more code will go here . . . . 

  public static void main ( String[] args )
  {
    TwoButtons demo  = new TwoButtons() ;
        

    . . . . more code will go here . . . . 
    
    demo.setSize( 200, 150 );     
    demo.setVisible( true );      

  }
}

. . . . more code will go here . . . . 

A layout manager needs to be assigned to this container. Use setLayout() with the FlowLayout() manager.

QUESTION 7:

Add this to the program.