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>

Recommended Answers

All 5 Replies

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...

thank you

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.