/*  MakeLoaders.java by Mark D. LaDue */

/*  April 9, 1998 */

/*  Copyright (c) 1998 Mark D. LaDue
    You may study, use, modify, and distribute this example for any purpose.
    This example is provided WITHOUT WARRANTY either expressed or implied.  */

/*  This applet exhibits the remarkable ability to create and use its
    own subclasses of AppletClassLoader.  To demonstrate that ability,
    it creates OuterLoader and InnerLoader classes and uses them to load
    and resolve a class.  */

import java.io.*;
import java.lang.reflect.*;
import java.net.*;
import netscape.applet.*;

public class MakeLoaders extends java.applet.Applet implements Runnable {

    Thread controller = null;
    InnerLoader inner = null;
    String urlstr = null;
    String dir = null;
    URL url = null;

    public void init() {

        urlstr = new String("http://www.rstcorp.com/hostile-applets/Com4Applets/MakeLoaders/");
        try {
            url = new URL(urlstr);
        }
        catch (MalformedURLException murle) {System.out.println("Bad URL");}
        dir = new String("Alt/");
    }

    public void start() {

        if (controller == null) {
        controller = new Thread(this);
        controller.start();
        }

    }

    public void stop() {}

    public void run() {

        Control.showConsole();  //Applets can pop up the Java Console too
        Class tricky = null;
        this.inner = new InnerLoader(url, dir);
        System.out.println("Created an InnerLoader: " + inner.toString());
        try {
            tricky = inner.loadClass("Dummy");
            System.out.println("Running the main() method of Dummy");
            Object[] argObj = {};
            Class[] argCl = {};
            tricky.getMethod("main", argCl).invoke(null, argObj);
        }
        catch(Exception ex) {
            System.out.println("Hosed:");
            ex.printStackTrace();
        }

    }

}
