java examples
Home Java Examples Resources Java Interview Questions
Brainpower SEO

How to read an applet parameters?

package com.javacoderanch.example.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.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 PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
  <title>Parameterized Applet</title>
    <applet code="com.javacoderanch.example.applet.AppletParameterExample" 
            height="150" width="350">
        <param name="name" value="Mr. Bean" />