Core java tutorial for beginners
A tutorial blog which explains different core concepts related to Java along with programming examples
Subscribe to Startertutorials.com's YouTube channel for different tutorial and lecture videos.

Categories: Applets. 8 Comments on Passing Parameters to Applets
3.9
(47)

In this article we will learn about passing parameters to applets using the param tag and retrieving the values of parameters using getParameter method.

 

Parameters specify extra information that can be passed to an applet from the HTML page. Parameters are specified using the HTML’s param tag.

 


Subscribe to our monthly newsletter. Get notified about latest articles, offers and contests.


Param Tag

 

The <param> tag is a sub tag of the <applet> tag. The <param> tag contains two attributes: name and value which are used to specify the name of the parameter and the value of the parameter respectively. For example, the param tags for passing name and age parameters looks as shown below:

 

<param name=”name” value=”Ramesh” />
<param name=”age” value=”25″ />

 

Now, these two parameters can be accessed in the applet program using the getParameter() method of the Applet class.

 

getParameter() Method

 

The getParameter() method of the Applet class can be used to retrieve the parameters passed from the HTML page. The syntax of getParameter() method is as follows:

 

String getParameter(String param-name)

 

Let’s look at a sample program which demonstrates the <param> HTML tag and the getParameter() method:

import java.awt.*;
import java.applet.*;
public class MyApplet extends Applet 
{
	String n;
	String a;
	public void init()
	{
		n = getParameter("name");
		a = getParameter("age");
	}
	public void paint(Graphics g)
	{
		g.drawString("Name is: " + n, 20, 20);
		g.drawString("Age is: " + a, 20, 40);
	}
}
/*
	<applet code="MyApplet" height="300" width="500">
		<param name="name" value="Ramesh" />
		<param name="age" value="25" />
	</applet>
*/

 

Output of the above program is as follows:

 

passing-parameters-to-applet

 

How useful was this post?

Click on a star to rate it!

We are sorry that this post was not useful for you!

Let us improve this post!

Tell us how we can improve this post?

Suryateja Pericherla

Suryateja Pericherla, at present is a Research Scholar (full-time Ph.D.) in the Dept. of Computer Science & Systems Engineering at Andhra University, Visakhapatnam. Previously worked as an Associate Professor in the Dept. of CSE at Vishnu Institute of Technology, India.

He has 11+ years of teaching experience and is an individual researcher whose research interests are Cloud Computing, Internet of Things, Computer Security, Network Security and Blockchain.

He is a member of professional societies like IEEE, ACM, CSI and ISCA. He published several research papers which are indexed by SCIE, WoS, Scopus, Springer and others.

Note: Do you have a question on this article or have a suggestion to make this article better? You can ask or suggest us by filling in the below form. After commenting, your comment will be held for moderation and will be published in 24-48 hrs.

8 Comments

You can follow any responses to this entry through the RSS 2.0 feed.

how to pass an integer value using param …

    In the Java code (class) you can convert a string into integer using Integer.parseInt() method.

    ok ok

this code is not working

it is so help full to me thanks.

Leave a Reply

Your email address will not be published. Required fields are marked *