Have an applet launch an other applet (this howto is deprecated)Tag(s): DEPRECATED
The idea is to load first a small Applet with a quick loading time, display a message to the user and then load a larger Applet.
[HTML (testappletloader.html)
<HTML><HEAD></HEAD><BODY>
<APPLET CODE="AppletLoader.class"
NAME="AppletLoader"
HEIGHT=200
WIDTH=200>
<PARAM NAME="appletToLoad" VALUE="SecondApplet0025">
<PARAM NAME="SecondAppletParm" VALUE="Hello World">
</APPLET></BODY></HTML>
import java.applet.Applet;
import java.applet.AppletStub;
import java.awt.*;
public class AppletLoader extends Applet
implements Runnable, AppletStub {
String appletToLoad;
Thread appletThread;
public void init() {
appletToLoad = getParameter("appletToLoad");
setBackground(Color.white);
}
public void paint(Graphics g) {
g.drawString("Loading the Second Applet ...", 30, 30);
}
public void run() {
try {
//
// REMOVE THIS
// for demo purpose only to see
// the "loading message!
//
Thread.sleep(2000);
//
Class appletClass = Class.forName(appletToLoad);
Applet realApplet = (Applet)appletClass.newInstance();
realApplet.setStub(this);
setLayout( new GridLayout(1,0));
add(realApplet);
realApplet.init();
realApplet.start();
}
catch (Exception e) {
System.out.println( e );
}
validate();
}
public void start(){
appletThread = new Thread(this);
appletThread.start();
}
public void stop() {
appletThread.stop();
appletThread = null;
}
public void appletResize( int width, int height ){
resize( width, height );
}
}
import java.awt.*;
public class SecondApplet0025 extends java.applet.Applet {
TextField tf;
public void init() {
System.out.println("Starting Second applet");
add(new Label("Second Applet"));
add(tf = new TextField( 10 ) );
String s = getParameter("SecondAppletParm");
tf.setText(s);
}
}
mail_outline
Send comment, question or suggestion to howto@rgagnon.com
Send comment, question or suggestion to howto@rgagnon.com