Webber: A Website Construction Application


PolyWindow.java


// A multi-window program frame - exit the Java system when the last window is closed

package library;

import java.awt.event.*;
import java.util.Enumeration;

public class PolyWindow extends DefaultWindow {
	private static int windowInstance;		// Window instance
	private static int windowCount;			// Window count
	private static LinkList windowList;		// Window list

	// Static initializer
	static {
		windowInstance = 0;			// Initialize window instance
		windowCount = 0;			// Initialize window count
		windowList = new LinkList();		// Create window list
	}

	// Constructor
	public PolyWindow(String title) {
		super(title);				// Call parent constructor
		windowList.addElement(this);		// Add new window to list
		setName("Poly" + windowInstance++);	// Set a unique window name
		++windowCount;				// Increment window count
	}
	
	// Override the window-closed method in DefaultWindow
	public void windowClosed(WindowEvent e) {
		windowList.removeElement(this);		// Remove window from list
		if (--windowCount<1) System.exit(0);	// Decrement window count
	}

	// Return the number of PolyWindow instances
	public static int getWindowCount() { return windowCount; }

	// Return an enumeration of all the active windows
	public static Enumeration elements() { return windowList.elements(); }

	// Get the window with the specified name from the window list
	public static PolyWindow getWindow(String name) {
		Enumeration e = elements();
		while (e.hasMoreElements()) {
			PolyWindow w = (PolyWindow)e.nextElement();
			if (w.getName().equals(name)) return w;
		}
		return null;
	}
}

Go To: Source Code