|
As we have discussed earlier in the Applet Section that we need the APPLET tag to start an applet both from an HTML document and also from an applet viewer.
The syntax for standard APPLET tag is
< APPLET [CODEBASE = codebaseURL] CODE = appletFile
[ALT = alternateText] [NAME = appletInstanceName]
WIDTH = pixels HEIGHT = pixels [ALIGN = alignment]
[VSPACE = pixels] [HSPACE = pixels]
>
[< PARAM NAME = AttributeName VALUE = AttributeValue>]
[< PARAM NAME = AttributeName2 VALUE = AttributeValue>]
. . .
[HTML Displayed in the absence of Java]
</APPLET>
We will talk about each of them in detail now:
1. CODEBASE : This is an optional attribute which is used to mention the base URL of the applet code. This acts as the directory which will be searched for the applet’s executable class file. The HTML document’s URL directory is used as the CODEBASE if this attribute is not specified.
2. CODE : This attribute is used to give the name of the file which contains the applet complied.class file .
3. ALT : This tag is used to specify a short text message that needs to be displayed if the browser understands the APPLET tag but can’t currently run Java applets. It is also an optional attribute.
4. NAME : Name as it suggest , it is used to specify a name for the applet instance. The Applets must be named in order for other applets on the same page to find them by name and communicate with them. To obtain an applet by name, use getApplet( ),
which is defined by the AppletContext interface.
It is also an optional attribute.
5. WIDTH AND HEIGHT : These attributes are needed to give the size (in pixels) of the applet display area.
6. ALIGN: This attribute defines the alignment of the applet. It is also an optional attribute.
7. VSPACE AND HSPACE : VSPACE specifies the space, in pixels, above and below the applet. HSPACE specifies the space, in pixels, on each side of the applet. They are also the optional attributes.
8. PARAM NAME AND VALUE : The PARAM tag allows to specify appletspecific arguments in an HTML page. Applets access their attributes with the getParameter( ) method.
9. HANDLING OLDER BROWSERS : The best way to design the HTML page to deal with older browsers is to include HTML text and markup within the <applet></applet> tags. If the applet tags are not recognized by the browser, we will see the alternate markup. If Java is available, it will consume the entire markup between the <applet></applet> tags and disregard the alternate markup.
Here’s the HTML to start an applet called SampleApplet in Java and to display a
message in older browsers:
<applet code="SampleApplet" width=200 height=40>
If we have a Java powered browser, we'd see & quote;
A Sample Applet "e; here.<p>
</applet>
|