Hi

i am new to java gui, i have trouble using color constructor.

please tell me what the problem .

thank you .

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

public class AnAppletSubclass1c extends Applet
{
	Color c = new Color(5,25,205);

	public void Color(int r,int g,int b);

	public void init()
	{
		System.err.println("Hello from AnAppletSubClass.init - the current value of n is " + n);
		c = Color.magenta;
	}
	public void paint(Graphics g) {
		setBackground(c);
		System.err.println("Hello from AnAppletSubClass.paint-- the current value of n is " + n);
		n++;
	}


	int n = 0;
}
<HTML>
	<HEAD>
		<TITLE> An Applet Subclass 1c </TITLE>
	</HEAD>
<BODY>

	<p>Here is the output of my  Program:</p>
	<APPLET CODE="AnAppletSubclass1c.class" WIDTH=150 HEIGHT=100>


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

Recommended Answers

All 4 Replies

please tell me what the problem .

I thought you would tell me what the problem you are experiencing instead of ask me to look through all of your code and try to figure out what it is???

OK, look at this link http://www.javacoffeebreak.com/faq/faq0052.html... It may be what you are looking for.

I thought you would tell me what the problem you are experiencing instead of ask me to look through all of your code and try to figure out what it is???

OK, look at this link http://www.javacoffeebreak.com/faq/faq0052.html... It may be what you are looking for.

i just don't know how to use color constructor

You created it correctly. The problem is you do not know how to apply the Color to your need... What you are doing is trying to apply the color to the applet background. That's why I gave you the link. If you want to use it for something else, please be more specific.

i just don't know how to use color constructor

Just remove this line

public void Color(int r,int g,int b);

and this line

c = Color.magenta;

Your initial declaration is just fine.

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.