import java.applet.Applet;
import java.applet.AppletStub;
import java.awt.Graphics;
import java.awt.GridLayout;
import java.awt.Label;

// This applet is responsible for loading another applet in the
// background and displaying the applet when it finishes loading.
// The name of the applet to load is supplied by a <PARAM> tag.
// For example:
// <PARAM name="applet" value="RealApplet">
// which would load an applet class called RealApplet
//
public class QuickLoader extends Applet implements Runnable, AppletStub
{
	String appletToLoad;
	Label label;
	Thread appletThread;

	public void init()
	{
// Get the name of the applet to load
		appletToLoad = getParameter("applet");

// If there isn't one, print a message
		if (appletToLoad == null) {
			label = new Label("No applet to load.");
		} else {
			label = new Label("Please wait - loading applet "+
				appletToLoad);
		}
		add(label);
	}

	public void run()
	{
// If there's no applet to load, don't bother loading it!
		if (appletToLoad == null) return;

		try {

// Get the class for the applet we want
			Class appletClass = Class.forName(appletToLoad);

// Create an instance of the applet
			Applet realApplet = (Applet)appletClass.newInstance();

// Set the applet's stub - this will allow the real applet to use
// this applet's document base, code base, and applet context.
			realApplet.setStub(this);

// Remove the old message and put the applet up

			remove(label);

// The grid layout maximizes the components to fill the screen area - you
// want the real applet to be maximized to our size.

			setLayout(new GridLayout(1, 0));

// Add the real applet as a child component
			add(realApplet);

// Crank up the real applet
			realApplet.init();
			realApplet.start();
		} catch (Exception e) {

// If we got an error anywhere, print it
			label.setText("Error loading applet.");
		}

// Make sure the screen layout is redrawn
		validate();
	}

	public void start()
	{
		appletThread = new Thread(this);
		appletThread.start();
	}

	public void stop()
	{
		appletThread.stop();
		appletThread = null;
	}

// appletResize is the one method in the AppletStub interface that
// isn't in the Applet class. You can use the applet resize
// method and hope it works.

	public void appletResize(int width, int height)
	{
		resize(width, height);
	}
}
