Java Reference
In-Depth Information
*/
void
void loadApplet ( String appletName , int
int h ) {
// appletName = ... extract from the HTML CODE= somehow ...;
// width = ditto
// height = ditto
try
int w , int
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
catch ( ClassNotFoundException e ) {
showStatus ( "Applet subclass " + appletName + " did not load" );
return
return ;
} catch
catch ( Exception e ){
showStatus ( "Applet " + appletName + " did not instantiate" );
return
return ;
}
ai . setSize ( w , h );
}
public
public void
void showStatus ( String s ) {
aa . getAppletContext (). showStatus ( s );
}
}
For Applet methods to work, two additional classes must be defined: AppletStub and Ap-
pletContext . The AppletStub is the tie-in between the applet and the browser, and the Ap-
pletContext is a set of methods used by the applet. In a real browser, they are probably im-
plemented separately, but I have combined them into one class (see Example 23-25 ) . Note
that the scope of applets that will work without throwing exceptions is rather limited, be-
cause so many of the methods here are, at present, dummied out. This AppletViewer is not a
full replacement for the standard AppletViewer ; it has been tested only with a basic Hello
World applet, and it is simply provided as a starting point for those who want to fill in the
gaps and make a full-blown applet viewer program or some other reflection-based tool that
works in a similar fashion.
Example 23-25. AppletAdapter.java, partial AppletStub, and AppletContext
public
public class
class AppletAdapter
AppletAdapter extends
extends Panel implements
implements AppletStub , AppletContext {
private
private static
long serialVersionUID = 1L ;
/** The status window at the bottom */
Label status = null
static final
final long
null ;
Search WWH ::




Custom Search