import java.applet.*; import java.awt.*; import java.net.*; import java.util.*; public class StubAppletViewer extends Frame implements AppletContext { Applet theApplet = null; TextField appletName = new TextField(32); Button reloadButton = new Button("Reload"); Button restartButton = new Button("Restart"); Vector theApplets = new Vector(); TextField status = new TextField(32); SimpleAppletStub theStub = new SimpleAppletStub(this); public static void main(String[] args) { StubAppletViewer sav = new StubAppletViewer("Stub Applet Viewer"); sav.init(); sav.pack(); sav.show(); } public void init() { add("Center", theStub); Panel p1 = new Panel(); p1.setLayout(new GridLayout(3, 1)); Panel p0 = new Panel(); p0.setLayout(new FlowLayout(FlowLayout.LEFT)); p0.add(new Label("URL: ")); p0.add(appletName); p1.add(p0); Panel p2 = new Panel(); p2.add(reloadButton); p2.add(restartButton); p1.add(p2); Panel p4 = new Panel(); p4.setLayout(new FlowLayout(FlowLayout.LEFT)); p4.add(new Label("Status: ")); status.setEditable(false); p4.add(status); p1.add(p4); add("South", p1); } public StubAppletViewer(String s) { super(s); } public void loadApplet(String name) { removeApplet(); if (name != null && !name.equals("")) { try { Class c = Class.forName(name); theApplet = (Applet) c.newInstance(); theApplet.setStub(theStub); theStub.add(theApplet); theApplets.addElement(theApplet); theApplet.init(); theStub.activate(); theStub.validate(); theApplet.start(); theApplet.resize(100, 100); pack(); } catch (ClassNotFoundException e) { System.err.println(e); } catch (InstantiationException e) { System.err.println(e); } catch (IllegalAccessException e) { System.err.println(e); } } } public void removeApplet() { if (theApplet != null) { theApplet.stop(); theStub.deactivate(); theApplet.destroy(); theStub.remove(theApplet); theApplets.removeElement(theApplet); theApplet = null; } } public void reload() { String name = appletName.getText(); if (theApplet != null) { Class c = theApplet.getClass(); name = c.getName(); removeApplet(); } loadApplet(name); } public void restart() { if (theApplet != null) { theApplet.stop(); theApplet.start(); } else loadApplet(appletName.getText()); } public boolean action(Event e, Object what) { if (e.target == restartButton) { restart(); return true; } else if (e.target == reloadButton) { reload(); return true; } else if (e.target == appletName) { loadApplet(appletName.getText()); return true; } return false; } public Image getImage(URL u) { return Toolkit.getDefaultToolkit().getImage(u); } public AudioClip getAudioClip(URL u) { return new NullAudioClip(); } public Applet getApplet(String s) { return null; } public Enumeration getApplets() { return (Enumeration) theApplets; } public void showDocument(URL url) {}; public void showDocument(URL url, String target) {}; public void showStatus(String s) { status.setText(s); } public void paint(Graphics g) { if (theApplet != null) theApplet.paint(g); } }