The two buttons are defined as below. (It would also work to declare and
construct each button in one statement:
JButton redButton = new JButton("Red").
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()
{
redButton = new JButton("Red");
grnButton = new JButton("Green");
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 . . . .
Now remember that GUI components need to be add()ed to the container.