/* related posts with thumb nails */

tag (or) How do you pass parameters to applets:

The param tag is used within an tag pair to pass input as parameters to an applet. Any number of parameters can be added to define a set constituting of name and value. They can be used to allow the page designer to specify different colors, fonts, urls or other data to be used by the applet.

The following two steps are included to pass parameters to applets:

· First, add the PARAM tag (with values) to the HTML source file.

· Second, add necessary code to the applet to retrieve these parameter values.

Syntax to pass parameters:

[attribute=value] .. >

[name=parameter-name value=”param-value”>]

[name=parameter-name value=”param-value”>]

...

Accessing Parameters: Parameter data can be accessed within the applet init() method using getParameter(). It takes one string argument and returns the VALUE attribute as a string. The argument name of the parameter should match the NAME attribute of the PARAM tag.

Syntax to access parameters:

String getParameter(String param-name);

Example: The following program demonstrates the usage of PARAM tag i.e. pas-sing parameters to an applet.

import java.applet.*;

import java.awt.*;

public class MyApplet extends Applet

{

String str=“Hi”;

public void init( )

{

str + = getParameter(“college”);

}

public void paint(Graphics g)

{

g.drawString(str,50,50); // Prints Hi Apoorva

}

}

For, which html file could be as follows, the parameter passed here is “college” whose value is “Apoorva”.





Related Topics:

0 comments:

Post a Comment