/* related posts with thumb nails */

Passing Parameters to Applets:

The param tag is used within an <APPLET> 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:

1. First, add the PARAM tag (with values) to the HTML source file.
2. Second, add necessary code to the applet to retrieve these parameter values.

Syntax to pass parameters:     

<APPLET   code="MyApp.class" width=200 height=200   
                                   [attribute=value] .. >
      [<param name=parameter-name value=”param-value”>]
      [<param 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”.<HTML>
  <APPLET  code="MyApp.class" width=200 height=200>
        <PARAM NAME = “college” VALUE = “Apoorva”>
Related Topics:


Post a Comment