import java.applet.*; import java.awt.*; import java.util.*; import java.net.URL; public class ContextAppletViewer extends Frame implements AppletContext { Applet theApplet = null; Panel appletPanel = new Panel(); TextField appletName = new TextField(32); Button loadButton = new Button("Load"); Button removeButton = new Button("Remove"); Button reloadButton = new Button("Reload"); Button restartButton = new Button("Restart"); Vector theApplets = new Vector(); TextField status = new TextField(32); public static void main(String[] args) { ContextAppletViewer cav = new ContextAppletViewer("Context Applet Viewer"); cav.show(); } public void init() { Panel p1 = new Panel(); p1.setLayout(new GridLayout(3, 1)); Panel p0 = new Panel(); p0.setLayout(new FlowLayout(FlowLayout.LEFT)); p0.add(new Label("Applet: ")); p0.add(appletName); p1.add(p0); Panel p2 = new Panel(); p2.add(loadButton); p2.add(removeButton); 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); appletPanel.setLayout(new BorderLayout()); add("Center", appletPanel); } public ContextAppletViewer(String s) { super("Context Applet Viewer"); init(); resize(400, 250); } public void loadApplet(String name) { removeApplet(); if (name != null && !name.equals("")) { try { Class c = Class.forName(name); theApplet = (Applet) c.newInstance(); appletPanel.add("Center", theApplet); theApplets.addElement(theApplet); theApplet.init(); theApplet.start(); validate(); } catch (Exception e) { showStatus(e.toString()); } } } public void removeApplet() { if (theApplet != null) { theApplet.stop(); theApplet.destroy(); theApplets.removeElement(theApplet); appletPanel.remove(theApplet); theApplet = null; validate(); repaint(); } } public void reload() { if (theApplet != null) { Class c = theApplet.getClass(); String name = c.getName(); removeApplet(); loadApplet(name); } } public void restart() { if (theApplet != null) { theApplet.stop(); theApplet.start(); } } 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 == loadButton) { loadApplet(appletName.getText()); return true; } else if (e.target == removeButton) { removeApplet(); 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); } }