import java.awt.*;
import javax.swing.*;

import gui.ColorButton;
import gui.ColorEvent;
import gui.ColorListener;

/**
 * A driver that  illustrates the use of the ColorButton class
 *
 * @author  Prof. David Bernstein, James Madison University
 * @version 1.0
  */
public class ColorButtonDriver implements ColorListener
{
    /**
     * Handle a colorChanged message (requried by ColorListener)
     *
     * @param event   The ColorEvent that generated the message
     */
    public void colorChanged(ColorEvent event)
    {
       System.out.println(event.getID() + "\t"+ event.getColor());
    }
    
    /**
     * The entry point
     */
    public static void main(String[] args)
    {
       ColorButton               button;       
       ColorButtonDriver         cbd;
       Container                 contentPane;
       JFrame                    frame;
       
       frame = new JFrame();
       contentPane = frame.getContentPane();
       contentPane.setLayout(new FlowLayout());

       cbd = new ColorButtonDriver();

       button = new ColorButton(Color.RED);
       button.setActionCommand("Foreground");       
       button.addColorListener(cbd);
       contentPane.add(button);
       
       button = new ColorButton(Color.BLUE);
       button.setActionCommand("Background");       
       button.addColorListener(cbd);
       contentPane.add(button);
       
       frame.setSize(400,200);
       frame.setVisible(true);
    }
    
}
