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

/***
 * This is a generic ApplicationAndApplet class that can be run as an 
 * applet or as a standalone application.
 * @author Mitch Fincher, October 1998 (Special thanks to Ruhul Alam)
**/
////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////
public class ApplicationAndApplet extends Applet implements Runnable {
////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////
public boolean stand_alone = false;
private Thread _main_thread = null;

////////////////////////////////////////////////////////////////
public ApplicationAndApplet()
////////////////////////////////////////////////////////////////
  {
    System.out.println("ApplicationAndApplet constructor. ");
  }
////////////////////////////////////////////////////////////////
  public String getAppletInfo()
////////////////////////////////////////////////////////////////
  {
    return "Name: ApplicationAndApplet";
  }

////////////////////////////////////////////////////////////////
  public void start()
////////////////////////////////////////////////////////////////
  {
    System.out.println("start()");
    if (_main_thread == null)
      {
	_main_thread = new Thread(this);
	_main_thread.start();
      }  
  }

////////////////////////////////////////////////////////////////
  public void stop()
////////////////////////////////////////////////////////////////
    {
      System.out.println("stop() ");
	if (_main_thread != null)
	{
	    _main_thread.stop();
	    _main_thread = null;
	}
    }

////////////////////////////////////////////////////////////////
  public void init()
////////////////////////////////////////////////////////////////
  {
    System.err.println("init().stand_alone: " + stand_alone);
  }

////////////////////////////////////////////////////////////////
  public void run()
////////////////////////////////////////////////////////////////
  {
    int i=0;
    while (++i<10)
      {
	try
	  {
	    repaint();
	    Thread.sleep(500);
	    System.out.println("   run()");
	    showStatus(i+" applet param javatype = "+getParameter("javatype"));
	  }
	catch (InterruptedException e)
	  {
	    System.err.println("Interrupterd:  " + e);
	    stop();
	  }
      }
  }

////////////////////////////////////////////////////////////////
  public String getParameter (String param)
////////////////////////////////////////////////////////////////
  {
    if(! stand_alone)
      return(super.getParameter(param));
    else
      return("stand alone.");
  }

////////////////////////////////////////////////////////////////
  public void showStatus (String param)
////////////////////////////////////////////////////////////////
  {
    if(! stand_alone)
      super.showStatus(param);
    else
	System.err.println("showStatus: " + param);
  }

////////////////////////////////////////////////////////////////
  public static void main (String args[]) {
////////////////////////////////////////////////////////////////

	Frame my_frame = new Frame();
	my_frame.resize(600,600);
	my_frame.show();

	ApplicationAndApplet app = new ApplicationAndApplet();
	app.stand_alone = true;
	my_frame.add("Center",app);

	app.init();
	app.show();
	System.err.println("standalone param javatype = : " + app.getParameter("javatype"));
	app.run();
	System.exit(0);
    }

} // class ApplicationAndApplet
