Running the Applet
If you were writing an application, you could invoke the Java interpreter from the command line to run the class. An applet, however, requires a browser environment, so you'll have to write some HTML to display the applet.
Writing the HTML
Listing 36.2 shows a simple Web page that includes the HelloApplet applet. This Web page will work with the appletviewer—you'll want to improve the HTML by adding a head, title, background color, and perhaps some text before you use it on your Web site.
Code Listing 36.2. helloApplet.html—You Must Write an HTML File to Test an Applet
<HTML> <BODY> <APPLET CODE="HelloApplet.class" WIDTH="200" HEIGHT="200"> </APPLET> </BODY> </HTML> |
Tip
Your HTML source file is not subject to the same strict ...
Get Platinum Edition Using XHTML™, XML, and Java™ 2 now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.