Putting an Applet on a Web Page

Applets are placed on a web page by using HTML, the markup language used to create web pages. HTML is a way to combine formatted text, images, sound, and other elements together and present them in a web browser. HTML uses markup commands called tags that are surrounded by < and > marks, including <img> for the display of images, <p> for  the insertion of a paragraph mark, and <h1> and </h1> to indicate the text that they surround is a heading.

The performance of HTML tags can be affected by attributes that determine how they function. The src attribute of an img tag provides the name of the image file that should be displayed, as in this example of HTML markup:

<img src="graduation.jpg">

This markup causes a web page to display the image stored in the file graduation.jpg. One way to place applets on a web page is to use applet tag and several attributes. The following HTML markup runs an applet on a page:

<applet code="StripYahtzee.class" codebase="javadir" height="300" width="400">
<p>Sorry, no dice ... this requires a Java-enabled browser.</p>
</applet>

The code attribute identifies the name of the applet’s class file. If more than one class file is being used with an applet, code should refer to the class that’s a subclass of the JApplet class.

The codebase applet contains the path of the folder or subfolder where the applet and related files can be found. If there is no codebase attribute, all files associated with the applet must be in the same folder as the web page that contains the applet. In the preceding example, codebase indicates that the StripYahtzee applet can be found in the javadir subfolder.

The height and width attributes designate the size of the applet window on the web page in pixels. It must be big enough to handle the things you are displaying in your applet.

In between the opening <applet> tag and the closing </applet> tag, you can provide some HTML markup to display to web users whose browsers either do not support Java or have Java turned off.

In the preceding example, the paragraph “Sorry, no dice....this requires a Java-enabled browser” is displayed in place of the applet in browsers that don’t run Java. You can put instructions here on how to download a Java-enabled browser from Oracle at www.java.com. You also can include hyperlinks and other HTML elements.

Another useful attribute, align, designates how an applet is displayed in relation to the surrounding material on the page, including text and graphics. The value align=”left” lines up an applet to the left of adjacent page elements and align=”right” to the right.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.145.57.254