/* ShowSortFrame.java:  visual demonstration of sorting algorithms.
 * (C) 1999 Neil Moore <neil@cs.uky.edu>
 *
 * This program may be freely distributed under the terms of the
 * GPL; see the file COPYING for more information.
 */
import java.awt.*;
import java.awt.event.*;

/**
 * The ShowSortFrame class provides a frame in which runs a ShowSort
 * applet.  It is started by ShowSort::launch.
 *
 * @see ShowSort
 * @see ShowSort#launch
 * @author Neil Moore <a href="mailto:neil@cs.uky.edu">
 *         &lt;neil@cs.uky.edu&gt;</a>
 * @version 0.1
 */
class ShowSortFrame extends Frame implements WindowListener {
	/**
	 * The ShowSort applet associated with this frame.
	 *
	 * @see ShowSort
	 */
	ShowSort applet;

	/**
	 * Create a new ShowSortFrame running a particular ShowSort.
	 *
	 * @param sort the ShowSort applet to use in this frame
	 * @param frameTitle the title to use for this frame
	 * @see ShowSort#launch
	 */
	public ShowSortFrame(ShowSort sort, String frameTitle) {
		super(frameTitle);
		applet = sort;
		
		add("Center",applet);
		applet.init();
		addWindowListener(this);
	}

	/**
	 * Part of the WindowListener interface.  This method stops and
	 * destroys this frame's applet, then exits.
	 *
	 * @param e a WindowEvent
	 * @see ShowSort#stop
	 */
	public void windowClosing(WindowEvent e) {
		Window originator = e.getWindow();

		if(originator.equals(this)) {
			this.dispose();
			applet.stop();
			applet.destroy();
			System.exit(0);
		}
	}

	public void windowActivated(WindowEvent e)   {}
	public void windowDeactivated(WindowEvent e) {}
	public void windowIconified(WindowEvent e)   {}
	public void windowDeiconified(WindowEvent e) {}
	public void windowOpened(WindowEvent e)      {}
	public void windowClosed(WindowEvent e)      {}
}
