Passing Parameters to Applets in Java

Run the java applet codes in BlueJ for easier implementation through BlueJ Appletviewer. 

import java.awt.*;
import java.applet.*;
/*
    <applet code="ParamDemo" width=400 height=100>
    <param name=script value=Java>
    <param name=specification value=Applet>
    <param name=popularity value=7>
    <param name=accountEnabled value=true>
    </applet>
 */
public class ParamDemo extends Applet
{
    String script,specification;
    int popularity;
    boolean active;
    public void start()
    {
        String param;
        script=getParameter("script");
        if(script==null)
            script="not found";
        specification=getParameter("specification");
        if(specification==null)
            specification="not found";
        param=getParameter("popularity");
        try
        {
            if(param!=null)
                popularity=Integer.parseInt(param);
            else
                popularity=0;
        }
        catch(NumberFormatException e)
        {
            popularity=-1;
        }
        param=getParameter("accountEnabled");
        if(param!=null)
            active=Boolean.valueOf(param).booleanValue();
    }
    public void paint(Graphics g)
    {
        g.drawString("Script : " + script , 0,20);
        g.drawString("Specification : " + specification , 0,30);
        g.drawString("Popularity : " + popularity , 0,55);
        g.drawString("Account Active : " + active , 0,70);
    }
}

Top