Difference between revisions of "Have an applet launch an other applet"

From CodeCodex

m (change the opening tag)
m (Reverted edits by Noemistegman (talk) to last revision by Nostromo)
 
Line 1: Line 1:
DNAアクティベーション
+
==Implementations==
 +
===Java===
 +
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.
  
サイキック/スピリチュアルカウンセラーのキャンデスによる、スピリチュアルなDNAアクティベーション。人生が変わり始めます。
+
[HTML (testappletloader.html)
 +
<pre class="java">
 +
<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>
 +
</pre>
 +
[JAVA source (AppletLoader.java)]
 +
<pre class="java">
 +
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 );
 +
  }
 +
}
 +
</pre>
 +
[SecondApplet0025.java for demonstration]
 +
<pre class="java">
 +
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);
 +
    }
 +
}
 +
</pre>
 +
try it [http://www.rgagnon.com/examples/testappletloader.html here.]
 +
[[Category:Java]]

Latest revision as of 21:37, 4 September 2012

Implementations[edit]

Java[edit]

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>

[JAVA source (AppletLoader.java)]

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 );
  }
}

[SecondApplet0025.java for demonstration]

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);
    }
}

try it here.