Core Java - [Applet Parameter]

♠ Posted by Unknown in at 04:26
Parameterized Applet Program

To pass parameter into applet program. We have to use <PARAM> tag of <APPLET> tag. <PARAM> tag have name option to  named parameter and value option to set the value of that parameter tag.

Java File

/*
<APPLET
CODE = HelloJavaParam.class
WIDTH = 400
HEIGHT = 200
ALIGN = MIDDLE>

<PARAM NAME = "string" VALUE = "Applet! ">
</APPLET>
*/

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

public class  HelloJavaParam extends Applet
{
String str;
public void init()
{
str = getParameter("string");
if(str == null)
str = "Java";
str = "Hello " + str;
}
public void paint(Graphics g)
{
g.drawString(str, 10, 100);
}
}


HTML File

<HTML>
<HEAD>
<TITLE>Applet Parameter</TITLE>
</HEAD>
<BODY>
<APPLET
CODE = "HelloJavaParam.class"
WIDTH = "400"
HEIGHT = "200"
ALIGN = MIDDLE>

<PARAM NAME = "string" VALUE = "Applet! ">
</APPLET>
</BODY>
</HTML>


Output
Image: Parameter Applet


In Applet code there is one <PARAM> tag which is used to pass parameter from web-browser to Java Applet program. The parameter is fetched using "getParameter()" applet method and return to string variable.


1 comments:

Thanks for Sharing this valuble information and itis useful for me and CORE JAVA learners.We also provides the best Online CORE JAVA Training classes.

Post a Comment