//*** Sample AppletHost to test class loading //*** README: Here's a sample invocation that'll work if // you're connected: // // java AppletHost http://condor.depaul.edu/dmumaugh/JDP/test/misc.class \ // misc // // The 1st command-line argument is the full URL, which includes the applet file // misc.class. // // The 2nd command-line argument is the name of the applet, misc. I should do // more work and extract the name from the URL (next release). // Below is the RemoteClassLoader that you'll need. import java.applet.Applet; import java.awt.Frame; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; import java.net.URL; public class AppletHost { public static void main(String[ ] args) throws Exception { if (args.length < 2) throw new Exception( "Usage: AppletHost "); URL url = new URL(args[0]); new AppletHost().do_it(url, args[1]); } private void do_it(URL url, String name) throws Exception { // Download and instantiate the applet. URL[ ] urls = {url}; RemoteClassLoader rcl = new RemoteClassLoader(urls); Class c = rcl.loadClass(name); Applet a = (Applet) c.newInstance(); new MyFrame(a, 800, 400); } } // Framed window in which to display the applet. class MyFrame extends Frame { public MyFrame(Applet a, int w, int h) throws Exception { addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { e.getWindow().dispose(); System.exit(0); }}); setTitle(a.getClass().getName()); setSize(w, h); add("Center", a); a.init(); show(); a.start(); } }