User-defined
parameters can be passed to an applet using <PARAM..> tag.
Each
<PARAM..> tag has a name
attribute and a value attribute.
Inside
an applet code, the applet can refer to that parameter by name to find its
value.
Parameters
are passed on an applet when it is loaded. We can define the init() method in the applet to fetch
the parameters defined in the <PARAM> tag.
The
getParameter() method is used to
access the parameters. It takes one string argument representing the name of
the parameter and returns a string containing the value of the parameter.
Ex:
Java
Code:
import java.awt.*;
import java.applet.*;
public class ParamApplet extends
Applet
{
String str;
public void init()
{
str=getParameter("name");
str="Welcome : " +str;
}
public void paint(Graphics g)
{
g.drawString(str,20,20);
}
}
HTML
Code:
<HTML>
<HEAD>
<TITLE>My Applet
Code</TITLE>
</HEAD>
<BODY>
<APPLET CODE=ParamApplet.class
WIDTH=500
HEIGHT=400>
<PARAM name="name"
value="Sachi">
</APPLET>
</BODY>
</HTML>
No comments:
Write comments