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>
Latest posts by Wayan (see all)
- How do I create a string of repeated characters? - September 1, 2023
- How do I convert datetime string with optional part to a date object? - August 28, 2023
- How do I split large excel file into multiple smaller files? - April 15, 2023