import java.awt.*;
import javax.swing.*;

/**
 * An example that uses checkboxes
 *
 * @version 1.0
 * @author  Prof. David Bernstein, James Madison Univeristy
 */
public class RadioButtonDriver
{
    /**
     * The entry point of the example
     *
     * @param args   The command line arguments
     */
    public static void main(String[] args)
    {
        Container       contentPane;
        JCheckBox       automobilesCB, planesCB, trainsCB;
        JLabel          titleLabel;
        JPanel          south;
        JTextArea       textArea;
	JFrame          frame;

	frame = new JFrame();
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        
        contentPane = frame.getContentPane();

        contentPane.setLayout(new BorderLayout());

        titleLabel = new JLabel();
        titleLabel.setText("A CheckBox Example");
        contentPane.add(titleLabel, BorderLayout.NORTH);


        textArea = new JTextArea(40,20);
        contentPane.add(textArea, BorderLayout.CENTER);

        south = new JPanel();
        south.setLayout(new FlowLayout());
        contentPane.add(south, BorderLayout.SOUTH);       

        planesCB = new JCheckBox("Planes");
        planesCB.setActionCommand("planesCB");
        planesCB.setMnemonic('P');
        south.add(planesCB, BorderLayout.WEST);

        trainsCB = new JCheckBox("Trains");
        trainsCB.setActionCommand("trainsCB");
        trainsCB.setMnemonic('T');
        south.add(trainsCB, BorderLayout.EAST);

        automobilesCB = new JCheckBox("Automobiles");
        automobilesCB.setActionCommand("automobilesCB");
        automobilesCB.setMnemonic('A');
        south.add(automobilesCB, BorderLayout.SOUTH);

        // Setup the observer
        CheckBoxHandler handler = new CheckBoxHandler(textArea);
        planesCB.addItemListener(handler);
        trainsCB.addItemListener(handler);
        automobilesCB.addItemListener(handler);
        
        // This is new
        // Setup the button group
        // This is different
        ButtonGroup group = new ButtonGroup();
        group.add(planesCB);
        group.add(trainsCB);
        group.add(automobilesCB);

        
	frame.setSize(400,400);
	frame.setVisible(true);
    }
}
