
-----------------------------------
user23
Sat Dec 10, 2011 9:30 pm

How can I pass through the color variable?
-----------------------------------
on a line like the following
public void  (int x,int y,int a,int b, "COLOR HERE")
What would I put in the color spot, to pass that value through and actually use it (would I have to still use the setColor line, and incorporate that value)?

Thanks

-----------------------------------
Zren
Sat Dec 10, 2011 9:46 pm

RE:How can I pass through the color variable?
-----------------------------------
If you're using the default graphics. You'd use an instance of Color from java.awt.Color. Yes you will need to tell the Graphics engine that you are now drawing in red.

-----------------------------------
user23
Sat Dec 10, 2011 10:35 pm

Re: How can I pass through the color variable?
-----------------------------------
I'm unsure of what would go into the "color here" part, so that I could pass through different colors each time as I run it, along with the different values for the other variables.

Thanks

-----------------------------------
Zren
Sat Dec 10, 2011 11:58 pm

RE:How can I pass through the color variable?
-----------------------------------
You'd need to declare a parameter variable similar to how you you defined the integers x,y,a, and b. Except this time the data type is 
import java.awt.Color;


-----------------------------------
user23
Sun Dec 11, 2011 12:59 am

Re: How can I pass through the color variable?
-----------------------------------
Yea I tried that, but   setColor (Color.c) doesn't work, while if the c was replaced with black there, it'd work fine, and black is the same color I'm passing through.  Is that not how it should be done?  I tried (c) and (Color c) in the brackets as well.

And when passing through black, I simply write it as text, correct?

-----------------------------------
Zren
Sun Dec 11, 2011 1:07 am

RE:How can I pass through the color variable?
-----------------------------------
Well I guess it wasn't for lack of trying.


public void blarg (Color c) {
    setColor(Color.green); // Using one of the static presets.
    setColor(new Color(1, 0.5, 0)); // New instance / Custom color
    setColor(c);
}


No. You don't just write blarg(black); as in that syntax, black is a variable. So unless you've declared a variable with the name black and it's data type is Color, it will not work.
