Tuesday 29 November 2011

APPLET Tag


The APPLET tag is used to start an applet from both an HTML document and from an applet viewer.

An applet viewer will execute each APPLET tag that it finds in a separate window, while web browsers like Netscape Navigator, Internet Explorer, and HotJava will allow many applets on a single page.

The syntax for the standard APPLET tag is shown here. Bracketed items are optional.

< 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>

CODEBASE :

CODEBASE is an optional attribute that specifies the base URL of the applet code, which is the directory that will be searched for the applet’s executable class file (specified by the CODE tag). The HTML document’s URL directory is used as the CODEBASE if this attribute is not specified. The CODEBASE does not have to be on the host from which the HTML document was read.

CODE :

CODE is a required attribute that gives the name of the file containing the applet’s compiled .class file. This file is relative to the code base URL of the applet, which is the directory that the HTML file was in or the directory indicated by CODEBASE if set.

ALT :

The ALT tag is an optional attribute used to specify a short text message that should be displayed if the browser understands the APPLET tag but can’t currently run Java applets. This is distinct from the alternate HTML you provide for browsers that don’t support applets.
THE
JAVA
LIBRARY
NAME :

NAME is an optional attribute used to specify a name for the applet instance. 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.

WIDTH AND HEIGHT :

WIDTH and HEIGHT are required attributes that give the size (in pixels) of the applet display area.

ALIGN :

ALIGN is an optional attribute that specifies the alignment of the applet. This attribute is treated the same as the HTML IMG tag with these possible values: LEFT, RIGHT, TOP, BOTTOM, MIDDLE, BASELINE, TEXTTOP, ABSMIDDLE,and ABSBOTTOM.

VSPACE :

AND HSPACE These attributes are optional. VSPACE specifies the space, in pixels, above and below the applet. HSPACE specifies the space, in pixels, on each side of the applet. They’re treated the same as the IMG tag’s VSPACE and HSPACE attributes.

PARAM :

NAME AND VALUE The PARAM tag allows to specify applet specific arguments in an HTML page.


The APPLET tag in HTML allows you to pass parameters to the applet. To retrieve a parameter,  the getParameter( ) method is used.

String getParameter(paramname)

It returns the value of the specified parameter in the form of a String object. Thus, for numeric and boolean values, you will need to convert their string representations into their internal formats. The paramname is the name of parameter specified in applet Tag.

Ex,
Create Applet

import java.awt.*;
import java.applet.*;

public class HtmlApplet extends Applet
{
     public void paint(Graphics g)
     {
           g.drawString(“Hello Java Applet”,10,20);
     }
}

Save this as HtmlApplet.java

Compile the file javac HtmlApplet.java

The compiled output file called HtmlApplet.class is placed in the same directory as source.

create Web page Html_Applet.html

<HTML>
     <HEAD>
           <TITLE> HtmlApplet </TITLE>
     </HEAD>
<BODY>
<APPLET CODE=HtmlApplet.class  HEIGHT=400  WIDTH=400>
</APPLET>
</BODY>
</HTML>

open this file in java enabled browser or open it in appletviewer which is the part of JDK. appletviewer  HtmlApplet.html

Posted by : Ruchita Pandya

No comments:

Post a Comment