AppletViewerpublic class AppletViewer extends Object
Fields Summary |
---|
JFrame | fThe main Frame of this program | static AppletAdapter | aaThe AppletAdapter (gives AppletStub, AppletContext, showStatus) | String | appNameThe name of the Applet subclass | Class | acThe Class for the actual applet type | Applet | aiThe Applet instance we are running, or null. Can not be a JApplet
until all the entire world is converted to JApplet. | final int | WIDTHThe width of the Applet | final int | HEIGHTThe height of the Applet |
Constructors Summary |
---|
AppletViewer(String appName)Construct the GUI for an Applet Viewer
super();
this.appName = appName;
f = new JFrame("AppletViewer");
f.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
f.setVisible(false);
f.dispose();
System.exit(0);
}
});
Container cp = f.getContentPane();
cp.setLayout(new BorderLayout());
// Instantiate the AppletAdapter which gives us
// AppletStub and AppletContext.
if (aa == null)
aa = new AppletAdapter();
// The AppletAdapter also gives us showStatus.
// Therefore, must add() it very early on, since the Applet's
// Constructor or its init() may use showStatus()
cp.add(BorderLayout.SOUTH, aa);
showStatus("Loading Applet " + appName);
loadApplet(appName , WIDTH, HEIGHT); // sets ac and ai
if (ai == null)
return;
// Now right away, tell the Applet how to find showStatus et al.
ai.setStub(aa);
// Connect the Applet to the Frame.
cp.add(BorderLayout.CENTER, ai);
Dimension d = ai.getSize();
d.height += aa.getSize().height;
f.setSize(d);
f.setVisible(true); // make the Frame and all in it appear
showStatus("Applet " + appName + " loaded");
// Here we pretend to be a browser!
ai.init();
ai.start();
|
Methods Summary |
---|
void | loadApplet(java.lang.String appletName, int w, int h)
// appletName = ... extract from the HTML CODE= somehow ...;
// width = ditto
// height = ditto
try {
// get a Class object for the Applet subclass
ac = Class.forName(appletName);
// Construct an instance (as if using no-argument constructor)
ai = (Applet) ac.newInstance();
} catch(ClassNotFoundException e) {
showStatus("Applet subclass " + appletName + " did not load");
return;
} catch (Exception e ){
showStatus("Applet " + appletName + " did not instantiate");
return;
}
ai.setSize(w, h);
| public static void | main(java.lang.String[] av)Main is where it all starts.
Construct the GUI. Load the Applet. Start it running.
new AppletViewer(av.length==0?"HelloApplet":av[0]);
| public void | showStatus(java.lang.String s)
aa.getAppletContext().showStatus(s);
|
|