Answer:
The two buttons are defined as below.
Adding Buttons
A skeleton of a constructor has been added to the program.
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()
{
super( title );
redButton = new JButton("Red");
grnButton = new JButton("Green");
. . . . more code will go here . . . .
setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
}
. . . . more code will go here . . . .
public static void main ( String[] args )
{
TwoButtons demo = new TwoButtons( "Click a Button") ;
demo.setSize( 200, 150 );
demo.setVisible( true );
}
}
Now remember that GUI components need to be add()ed to the container.