How to read an Applet Parameters in Java?

Below java code shows how to read applet parameters:

[java]
/****************************************************************************************
* Created on 07-2011 Copyright(c) https://kodehelp.com All Rights Reserved.
****************************************************************************************/
package com.kodehelp.java.applet;

import java.applet.Applet;
import java.awt.*;

/**
* This class shoes you code snippet for getting or reading the Parameter value.
* Created by Vigilance India.
* User: https://kodehelp.com
* Date: Jul 31, 2011
*/
public class AppletParameter extends Applet {
private String param="";
public void init(){
//In this init() method of Applet we will be reading the parameter
//from applet tag definition in the HTML file
param = getParameter("param");
}

public void paint(Graphics g) {
g.setColor(Color.BLUE);
g.drawString("Hi here is your parameter " + param, 0, 0);
}
}
[/java]

[html]
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Parameterized Applet</title>
</head>
<body>
<applet code="com.kodehelp.java.applet.AppletParameter"
height="150" width="350">
<param name="param" value="Parameter Value" />
</applet>
</body>
</html>
[/html]

Please Post Your Comments & Reviews

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