How to read an Applet Parameters in Java?

Below java code shows how to read applet parameters:

/****************************************************************************************
 * Created on 07-2011 Copyright(c) http://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: http://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);
    }
}
<!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>

Please Post Your Comments & Reviews

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.