problem using color constructor
Hi
i am new to java gui, i have trouble using color constructor.
please tell me what the problem .
thank you
Code:
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;
}
Code:
<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>
Re: problem using color constructor
Maybe you should tell us what the problem is. Provide full errors if you got them. We need information to help you out.
Re: problem using color constructor
i just dont know have to use color constructor
my error is "error: missing method body, or declare abstract
public void Color(int r,int g,int b); "
thank you
Re: problem using color constructor
Well, you have a method called 'public void Color(int r, int g, int b);' first of which that is wrong, is that you didn't declare it abstract and it has no body, so an error for that. Next, you don't need to define constructors of existing classes. Remove the line and your code should work fine.
Re: problem using color constructor
thank you
it works but what if i want to use one of the Color class constructors ex:" Color(int r, int g, int b)"
Re: problem using color constructor
You are, when you use an import statement you get access to any class in the import statement, or the directory is you use the asterisk (*). You don't define the constructors (or anything else for existing, imported classes), you simply use them. Check the API to see all the things you have access to in a class.
Re: problem using color constructor
Thank you
ok if you going to take a look at this website Java Platform SE 6 , its says there i have to Creates an opaque sRGB color with the specified red, green, and blue values in the range (0 - 255). The actual color used in rendering depends on finding the best match given the color space available for a given output device. Alpha is defaulted to 255.
please if you have any clue please help me
thank you
Re: problem using color constructor
I think that sunde know what the API states. Your problem is that you cannot create your own pseudo-method. Just get rid of this line:
Code:
public void Color(int r,int g,int b);
It's not doing anything useful but is just causing errors.
Re: problem using color constructor
I think one of the problems you are running into is the thought that the onus is on you, but it is not. The Constructors you see in the constructor summary are defined in the java class library, when you use an import statement, you are getting access to them. Erase the line Fubar mentioned and it should work fine.
Re: problem using color constructor
Thank you guys now i understand it , very helpful :)