Home Java Example Java Applet The APPLET Tag in Detail

Related Tutorials


 
 

Share on Google+Share on Google+

The APPLET Tag in Detail

Advertisement
In this section you will learn to use the APPLET tag.

The <APPLET> Tag in Detail

     


After understanding a simple Java-enabled Web page lets explore the APPLET tag now. The format of this tag is given below:

[<]APPLET attributes[>]
applet_parameters
alternate_content
[</]APPLET[>] 

<APPLET> Tag Attributes in detail.

The three attributes of this tag are CODE/CODEBASE, WIDTH, and HEIGHT. One another point to note here that when we build <APPLET> tags the words such as APPLET and CODEBASE can be typed in either way as shown. 
The APPLET tag supports a number of standard attributes. The majority of these attributes are nearly identical to the attributes of the IMG tag (to be discussed later in this chapter). The three required attributes are CODE/CODEBASE, WIDTH, and HEIGHT. The following list describes each attribute and its meaning. Bold font indicates something you should type in exactly as shown except that letters don't need to be uppercase. To substitute a value for the word in italics, we use Italic font.
Square brackets indicate that the contents of the brackets are optional. Lets tweak the example below.

[<] APPLET
[CODEBASE = codebaseURL]
CODE = appletFile 
[ALT = alternateText]
[NAME = appletInstanceName]
WIDTH = pixels
HEIGHT = pixels 
[ALIGN = alignment] 
[VSPACE = pixels]
[HSPACE = pixels]
>
[< PARAM NAME = appletParameter1 VALUE = value >]
[< PARAM NAME = appletParameter2 VALUE = value >]
. . .
[alternateHTML]
[</]APPLET[>]

CODEBASE = codebaseURL
This attribute is used to specify the base URL of the applet -- the directory or folder that contains the applet's code. The document's URL is used.

if this attribute is not specified.

CODE = appletFile
This file is relative to the base URL of the applet and it cannot be absolute. This required attribute gives the name of the file that contains the applet's compiled Applet subclass. 

ALT = alternateText
Any text that should be displayed is specified by this optional attribute if the browser understands the APPLET tag but can't run Java applets.

NAME = appletInstanceName
This optional attribute specifies a name for the applet instance. With the help of this attribute it is possible for applets on the same page to find (and communicate with) each other.

WIDTH = pixels
HEIGHT = pixels

The initial width and height (in pixels) of the applet is given by these attributes to display area, not counting any windows or dialogs that the applet brings up.

ALIGN = alignment
This required attribute specifies the alignment of the applet with the same possible values (and have the same effects) as those for the IMG tag: left, right, top, texttop, middle, absmiddle, baseline, bottom, absbottom.

  • left-Aligns the applet at the left margin. The left and right values allow text to flow around the applet. (For spacing around the applet, see the VSPACE and HSPACE attributes.)
  • right-Aligns the applet at the right margin.
  • top-Aligns the applet with the topmost item on the current line in the HTML file.
  • texttop-Aligns the applet with the top of the tallest text in the current line of the HTML file.
  • middle-Aligns the applet with the middle of the baseline of the text in the current line of the HTML file.
  • absmiddle-Aligns the middle of the applet with the middle of the largest item (text or otherwise) in the current line of the HTML file.
  • baseline-Aligns the bottom of the applet with the baseline of the current line of the HTML file.
  • bottom-Equivalent to baseline.
  • absbottom-Aligns the bottom of the applet with the lowest item (text or otherwise) in the current line of the HTML file. 

VSPACE = pixels
HSPACE = pixels
These optional attributes are used to specify the number of pixels above and below the applet (VSPACE) and on each side of the applet (HSPACE). They're used the same way as the IMG tag's VSPACE and HSPACE attributes.

< PARAM NAME = appletParameter1 VALUE = value >
The only way to specify applet-specific parameters is to use the <PARAM> tags. Applets read user-specified values for parameters with the getParameter() method.

alternateHTML
If we use this <applet> tag in an HTML page to be viewed by the browser, probably the browser will ignore the <APPLET> and <PARAM> tags that doesn't understand the <APPLET> tag. Instead of interpreting any other HTML code between the <APPLET> and </APPLET> tags. Java-compatible browsers ignore this extra HTML code.

Advertisement

If you enjoyed this post then why not add us on Google+? Add us to your Circles



Liked it!  Share this Tutorial


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: June 14, 2007

Related Tutorials