O'Reilly logo

Platinum Edition Using XHTML™, XML, and Java™ 2 by Andrew H. Watt, Mike Morgan, Jim O'Donnell, Eric Ladd

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required