FileDocCategorySizeDatePackage
AppApp.javaAPI DocExample1332Tue Mar 13 22:36:10 GMT 2001None

AppApp.java

import java.awt.*;
import java.awt.event.*;
import java.applet.*;

/**
 * Example of a class that can be used as an Applet or an Application
 * @author Ian F. Darwin, ian@darwinsys.com
 * @version #Id$
 */
public class AppApp extends Applet {
	boolean inAnApplet = true;
	Label status;		// for Application showStatus()

	public void init() {
		add(new Label("This is my demo Applet"));
		showStatus("My applet is running");
	}

	public static void main(String[] av) {
		AppApp app = new AppApp();
		final Frame f = new Frame("AppApp Demo");
		f.addWindowListener(new WindowAdapter() {
			public void windowClosing(WindowEvent e) {
				f.hide();
				f.dispose();
			}
		});
		f.setLayout(new BorderLayout());
		app.inAnApplet = false;
		f.add("Center", app);
		// Must do this before init() since init() may use showStatus()
		f.add("South", app.status = new Label());
		f.setSize(300, 200);
		app.status.setSize(f.getSize().width, app.status.getSize().height);

		// Here we pretend to be a browser!
		// A fancier version would make an AppletStub and pass it
		// into the Applet with getAppletStub().
		app.init();
		app.start();

		f.setVisible(true);
	}
	public void showStatus(String s) {
		 if (inAnApplet) {
			 super.showStatus(s);	// call version in Browser
		 } else {
			 status.setText(s);		// do it yourself.
		 }
	}
}