ProblemYou need to deploy a Java applet. SolutionUse an <applet> tag in an HTML page. DiscussionWhile 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 or lowercase, with a preference for lowercase because the emerging standard XHTML[1] requires lowercase. 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. It was also common to omit the quotation marks around attribute values. You still see old pages done this way and old books or web pages recommending this. You may even see a few examples of that in old code of mine! The most common way to embed a Java applet is using an <applet> tag. Other tags for applets include <object> and <embed>, which I discuss briefly in Recipe 23.6. The <applet> tag has three required parameters (code, width, and height) and several optional ones. Table 18-1 lists these parameters.
You may also wish to pass some parameters in to the applet. Since an applet has no main method, there is no command-line communication with the applet. Hence, the applet parameters are included in the HTML page: the <param> tags go between the <applet> and </applet> tags. The following HTML file demonstrates many of these parameters: <applet code="DemoApplet.class" width="400 " height="75" codebase="http://www.darwinsys.com/applets/" > <param name="text" value="Java is fun!"> <hr / > If you were using a Java-enabled browser, you would see the graphical results instead of this paragraph. <hr /> </applet> |