How do I read an applet parameters?

package org.kodejava.applet;

import java.applet.Applet;
import java.awt.Color;
import java.awt.Graphics;

public class AppletParameterExample extends Applet {
    private String name = "";

    public void init() {
        // Here we read a parameter named name from the applet tag definition
        // in our html file.
        name = getParameter("name");
    }

    public void paint(Graphics g) {
        g.setColor(Color.BLUE);
        g.drawString("Hello " + name + ", Welcome to the Applet World.", 0, 0);
    }
}

Now we have the applet code ready. To enable the web browser to execute the applet create the following html page.

<!DOCTYPE html>
<html lang="en">
<head>
    <title>Parameterized Applet</title>
</head>
<body>
<applet code="org.kodejava.applet.AppletParameterExample"
        height="150" width="350">
    <param name="name" value="Mr. Bean"/>
</applet>
</body>
</html>
** Deprecated: The Applet API is deprecated since JDK 9, no replacement.
Wayan

Leave a Reply

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