Hello with Parameters

/* Hello World Applet with parameters */

import java.awt.Graphics;
import java.awt.Font;
import java.awt.Color;

public class Hellojoe extends java.applet.Applet {

Font f = new java.awt.Font("TimesRoman",Font.BOLD,36);
String name;
public void init() {
name = getParameter("name");
name = "Hello " + name;
}
public void paint(Graphics g) {
g.setFont(f);
g.setColor(Color.red);
g.drawString(name, 5, 50);
}
}

The getParameter line accepts the parameter from the
HTML code. The 'name' variable is then concatenated with
"Hello" and it is ready for execution.

 

The HTML code to place the applet on a page and send it parameters is given below.

<p><applet code="Hellojoe.class" width="400" height="60">
<
param name="name" value="Joe from Kokomo"></applet></p>

The applet window will be 400 X 60 pixels and it will accept "Joe from Kokomo" as the name parameter. The output is shown below.

Return