import java.applet.Applet; import java.awt.*; import java.awt.event.*; /** (C) 2000 Charles Consulting, LLC
Class which allows applet to be executed as application. Derived class should call setupApplet to perform usual browser functions.

Class should also implement a main function:

public static void main(String args[])
{
Subclass applet = new Subclass( );
applet.setupApplet(args);
}
*/ public abstract class StandAloneApplet extends Applet { /** called to setup applet */ protected void setupApplet( String args[] ) { int width, height; if ( args.length != 2 ) { // no command-line arguments width = 300; height = 200; } else { width = Integer.parseInt( args[ 0 ] ); height = Integer.parseInt( args[ 1 ] ); } // create window in which applet will execute Frame applicationWindow = new Frame( getTitle( )); applicationWindow.addWindowListener( new WindowAdapter() { public void windowClosing( WindowEvent e ) { System.exit( 0 ); } } ); resize(width,height); // call applet's init and start methods init(); start(); // attach applet to center of window applicationWindow.add( this); // set the window's size applicationWindow.setSize( width, height ); // showing the window causes all GUI components // attached to the window to be painted applicationWindow.show(); } /** return desired title */ abstract protected String getTitle( ); }