CIS 20.1
An Applet with Parameters


The applet's real estate is the area within the border

Source

AnAppletWithParms.java:
import java.applet.*;
import java.awt.*;

public class AnAppletWithParms extends Applet {
	public void init() {
		String parmString =  getParameter("number");
		System.err.println("The single parameter: " + parmString);
		n = Integer.parseInt(parmString);
		setBackground(Color.blue);
	}

	public void paint(Graphics g) {
		System.out.println("In paint: n = " + n);
		n++;
	}

	int n;
} 

Description and Objective

An applet that accepts a parameter

Notes

Parameters to Applets Specifying the Parameters in the HTML file Retrieving the Parameter's Value in the Applet

This Applet's Behavior

The HTML File The AnAppletWithParms Class

Things to Do

API work Playing with the Applet

Place the following three applets on a single page:

  1. Go back to the AppletSubClass example and pass in three integers corresponding to an RGB value and use the appropriate Color constructor to set the background color.
  2. Modify AnAppletWithParms so that it accepts three parameters: operand1, operand2, and operator. If operator is a +, the sum of the two numbers is sent to System.out, similarly for -, *, and /
  3. Same as the first applet, but this time, the parameter should be the name of a color (you can use names corresponding to several of the color constants in the Color class-- or use your own color names).