import java.applet.*; import java.awt.*; public class SimpleAppletViewer extends Frame { Applet theApplet = null; Panel appletPanel = new Panel(); TextField appletName = new TextField(32); Button reloadButton = new Button("Reload"); Button restartButton = new Button("Restart"); public static void main(String[] args) { SimpleAppletViewer sav = new SimpleAppletViewer(); sav.show(); } public SimpleAppletViewer() { super("Simple Applet Viewer"); init(); resize(400, 200); } protected void init() { Panel p1 = new Panel(); p1.setLayout(new GridLayout(2, 1)); p1.add(appletName); Panel p2 = new Panel(); p2.add(reloadButton); p2.add(restartButton); p1.add(p2); add("South", p1); appletPanel.setLayout(new BorderLayout()); add("Center", appletPanel); } 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); theApplet.init(); theApplet.start(); validate(); } 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(); theApplet.destroy(); appletPanel.remove(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 super.handleEvent(e); } }