Frames: Separate Top-Level Windows

User-Interfaces often need to temporarily display more information or ask for more input. Popup-menus and Dialog Boxes are simple forms of this, but have their own classes the AWT. An applet may also wish to become stand-alone, i.e. continue even when a new document is loaded in the browser. An independent window is created through the Frames class. (Note: for some unknown reason this example no longer works with Netscape Navigator but it does work with Microsoft Internet Explorer.)

Most of the source for this applet is:

public class FrameApplet extends Applet {
    public void init() {
	add(new Button("Open New Window"));
    }
    public boolean action (Event evt, Object arg) {
	if ("Open New Window".equals(arg)) {
	    TestWindow theWindow = new TestWindow();
	}
	return true;
    }
}

class TestWindow extends Frame {
    TestWindow() {
	super("Test Window");
	setLayout(new FlowLayout(FlowLayout.CENTER));
	resize(150, 50);
	add(new Button("Close"));
	show();
    }
    public boolean action (Event evt, Object arg) {
	if ("Close".equals(arg))
	    dispose();
	return true;
    }
}