import ActionFrame;
import FrameEditor;
import SquarePuzzleApp;
import javax.swing.*;
import java.awt.event.*;

public class FrameEditorTester extends JFrame implements ActionListener{
    
    private static long startTime;

    public FrameEditorTester(ActionFrame editor) {
        startTime = System.currentTimeMillis();
        editor.addActionListener(this);     // Test code is in charge
                                            // of handling "Quit"s.
    }
    
    public static void main (String[] args) {
        ActionFrame gameFrame = new SquarePuzzleApp(4,4);
        gameFrame.pack();
        gameFrame.setVisible(true);
        ActionFrame editFrame = new FrameEditor(gameFrame);
                                // Your constructor will have to
                                // register editFrame as ActionListener
                                // with gameFrame.
        editFrame.pack();
        editFrame.setVisible(true);
        editFrame.addWindowListener(new WindowAdapter() {
                public void windowClosing(WindowEvent e) {
                    doQuit();
                }});
        JFrame f = new FrameEditorTester(editFrame);
    }
    
    public void actionPerformed (ActionEvent e) {
        // Process "Quit" ActionCommand from editFrame.
        String s = e.getActionCommand();
        if (s != null)
            if (s.equals("Quit"))
                doQuit();
    }
    
    public static void doQuit() {
        System.out.println("Total elapsed time: " + ((System.currentTimeMillis() - startTime)/1000) + " seconds.");
        System.exit(0);
    }
}

