/* related posts with thumb nails */
· 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”>] ...
[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”.
0 comments:
Post a Comment