Java Reference
In-Depth Information
Figure 23-2. My AppletViewer showing simple applet
Example 23-24 is the code for the main part of the AppletViewer , which creates a JFrame
and then loads the Applet class dynamically and adds it to the JFrame .
Example 23-24. AppletViewer.java main program
public
public class
AppletViewer {
/** The main Frame of this program */
JFrame f ;
/** The AppletAdapter (gives AppletStub, AppletContext, showStatus) */
static
class AppletViewer
static AppletAdapter aa = null
null ;
/** The name of the Applet subclass */
String appName = null
null ;
/** The Class for the actual applet type */
Class <?> ac = null
null ;
/** The Applet instance we are running, or null. Can not be a JApplet
* until all the entire world is converted to JApplet. */
Applet ai = null
null ;
/** The width of the Applet */
final
final int
int WIDTH = 250 ;
/** The height of the Applet */
final
final int
int HEIGHT = 200 ;
/** Main is where it all starts.
* Construct the GUI. Load the Applet. Start it running.
*/
public
public static
static void
void main ( String [] av ) {
new
new AppletViewer ( av . length == 0 ? "HelloApplet" : av [ 0 ]);
}
/** Construct the GUI for an Applet Viewer */
AppletViewer ( String appName ) {
super
super ();
this
this . appName = appName ;
f = new
new JFrame ( "AppletViewer" );
Search WWH ::




Custom Search