01: //*** Sample AppletHost to test class loading
02: //*** README: Here's a sample invocation that'll work if
03: //            you're connected:
04: //
05: // java AppletHost http://condor.depaul.edu/dmumaugh/JDP/test/misc.class \
06: //    misc
07: //
08: // The 1st command-line argument is the full URL, which includes the applet file
09: // misc.class.
10: //
11: // The 2nd command-line argument is the name of the applet, misc. I should do
12: // more work and extract the name from the URL (next release).
13: // Below is the RemoteClassLoader that you'll need.
14: 
15: import java.applet.Applet;
16: import java.awt.Frame;
17: import java.awt.event.WindowAdapter;
18: import java.awt.event.WindowEvent;
19: import java.net.URL;
20: public class AppletHost {
21:     public static void main(String[ ] args) throws Exception {
22:         if (args.length < 2) 
23:             throw new Exception(
24:                 "Usage: AppletHost <URL> <applet name>");
25:         URL url = new URL(args[0]);
26:         new AppletHost().do_it(url, args[1]);
27:     }
28:     private void do_it(URL url, String name) throws Exception {
29:         // Download and instantiate the applet.
30:         URL[ ] urls = {url};
31:         RemoteClassLoader rcl = new RemoteClassLoader(urls);
32:         Class c = rcl.loadClass(name);
33:         Applet a = (Applet) c.newInstance();
34:         new MyFrame(a, 800, 400);  
35:     }
36: }
37: // Framed window in which to display the applet.
38: class MyFrame extends Frame {
39:     public MyFrame(Applet a, int w, int h) throws Exception {
40:         addWindowListener(new WindowAdapter() {
41:             public void windowClosing(WindowEvent e) {
42:                 e.getWindow().dispose();
43:                 System.exit(0);
44:             }});    
45:         setTitle(a.getClass().getName());
46:         setSize(w, h);   
47:         add("Center", a);
48:         a.init();             
49:         show();           
50:         a.start();        
51:     }
52: }