package tictactoe.pres;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import util.ActionPanel;

public class MasterPanel extends ActionPanel {

    protected JButton finalizeButton;

    /**
     * Construct a new Panel containing some buttons used to
     * facilitate editing the game appearance.
     */
    public MasterPanel() {
	this.setLayout(new GridLayout(1,0));
	finalizeButton = new JButton("Finalize");
	finalizeButton.setActionCommand("TTTFinalize");
	this.add(finalizeButton);
    }

    /**
     * Registers <code>listener</code> to receive ActionEvents
     * from the reactive subcomponents of the panel.  This
     * wrapper function invokes the addActionListener method of each
     * subcomponent.
     *
     * @param listener Event handler to register with the 
     * panel components.
     */
    public void addActionListener(ActionListener listener) {
	finalizeButton.addActionListener(listener);
    }
    
    /**
     * Runs a quick test of the class code.
     *
     * @param args Command-line arguments (ignored).
     */
    public static void main (String[] args) {
	JFrame f = new JFrame();
	MasterPanel masterPanel = new MasterPanel();
	masterPanel.addActionListener(new ActionListener() {
		public void actionPerformed(ActionEvent e) {
		    System.out.println("ActionCommand: "+e.getActionCommand());
		    System.out.println("Action source: "+e.getSource());
		}});
	f.getContentPane().add(masterPanel);
	f.pack();
	f.setVisible(true);
	f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    }
}

