i need to Pass in three integers corresponding to an RGB value and use the appropriate Color constructor to set the background color.

import java.applet.*;
import java.awt.*;

public class AnAppletSubclass2b extends Applet {
	int r;
	int g;
	int b;
	//Color color = new Color (r,g,b);
	public void init()
	{
		String parmStringRED =  getParameter("red");
		 r = Integer.parseInt(parmStringRED);
		String parmStringGREEN =  getParameter("green");
		 g = Integer.parseInt(parmStringGREEN);
		String parmStringBLUE =  getParameter("blue");
		 b = Integer.parseInt(parmStringBLUE);
		Color color = new Color (r,g,b);
		System.err.println("The parameter are: red: " + parmStringRED + ", green: " + parmStringGREEN + ", blue: " + parmStringBLUE);

		setBackground(color);
	}

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

	int n;
}
<HTML>
	<HEAD>
		<TITLE> AnApplet With Parms </TITLE>
	</HEAD>
<BODY>

	<p>Here is the output of my  Program:</p>
	<APPLET CODE="AnAppletSubclass2b.class" WIDTH=150 HEIGHT=100>
		<PARAM name="red" value="25" >
		<PARAM name="green" value="250">
		<PARAM name="blue" value="250">


	</APPLET>
</BODY>
</HTML>

why do u think this is not the right way? it works doesnt it??
and btw, whats with that paint method() ???

The OP posted one earlier with the same code.

Anyway, I think I got what the OP wants. He/she wants to add the part that the program asks user to enter a color value. Then apply the color to the applet background... The code is on the right track, but you just simply need to add the input part and verify the value before applying the value...

The OP posted one earlier with the same code.

Anyway, I think I got what the OP wants. He/she wants to add the part that the program asks user to enter a color value. Then apply the color to the applet background... The code is on the right track, but you just simply need to add the input part and verify the value before applying the value...

Ohh I get it...thx :)

@OP please write what you want clearly..

You should probably add a small check to make sure the integers added don't fall out of the 0-255 range. Maybe cast them as integer as well in case the integer's input is as a decimal.

This article has been dead for over six months. Start a new discussion instead.