PASSING PARAMETERS TO APPLET

One can supply user-defined parameters to an applet using tag. Each tag has a name attribute such as color,and a value attribute such as red. Inside the applet code, the applet can refer to that parameter by name to find its value. For e.g. the color of the text can be changed to red by an applet using a tag as follows

      <applet.....>

                   <param=color value="red">

      </applet> 

    Similarly we can change the text to be displayed by an applet by supplying new text to the applet through a <param. ...> tag as shown below. 

       <param name=text value = “xyz” >

Passing a parameters to an applet is similar to passing parameters to main() method using command line arguments. To set up and handle parameters, we need to do two things. 

1) Include appropriate tags in the HTML document. 

2) Provide code in the applet to pass these paraments.



Parameters are passed to an applet when it is loaded. We can define the init() method in the applet to get hold of the parameters defined in the <param>  tags. This is done using the getparameter() method, which takes one string argument representing the name of the parameter and returns a string containing the value of that parameter.