O'Reilly logo

Java Cookbook by Ian F. Darwin

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

Embedding Java in a Web Page

Problem

You need to deploy a Java applet.

Solution

Use an APPLET tag in an HTML page.

Discussion

While this is not the place for a dissertation on the details of HTML, you should at least know that HTML is a tag-based textual language for writing web pages. The tags (officially called elements) have short names, such as P for paragraph and A for anchor (hyperlink). Tag names can be written in uppercase (as I do in this book) or lowercase, but be consistent. Tags are surrounded by angle brackets, < and >. Modifiers, called attributes, go between the tag name and the close angle brackets. For example, the body of a web page might be introduced by <BODY BGCOLOR=WHITE>, which gives that page the specified background color. Most tags, including BODY and P, have a corresponding end tag, consisting of a forward slash character (/) and the name of the tag. A paragraph, for example, should begin with <P> and end with </P>. In days of yore, it was common to simply use <P> between paragraphs, but this mistake stems from not understanding the nature of HTML tags as containers. You still see old pages done this way and, occasionally, very old books or web pages recommending this.

The most common method of embedding a Java applet is to use an APPLET tag. Other tags include OBJECT and EMBED, which I’ll discuss briefly in Section 23.6. The APPLET tag has three required parameters (CODE/OBJECT, WIDTH, and HEIGHT) and several optional ones. Table 17-1 lists these ...

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