Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 How can I pass through the color variable?
Index -> Programming, Java -> Java Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
user23




PostPosted: Sat Dec 10, 2011 9:30 pm   Post subject: 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
Sponsor
Sponsor
Sponsor
sponsor
Zren




PostPosted: Sat Dec 10, 2011 9:46 pm   Post subject: 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




PostPosted: Sat Dec 10, 2011 10:35 pm   Post subject: 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




PostPosted: Sat Dec 10, 2011 11:58 pm   Post subject: 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 Color. You'd also need a unique variable name.

Of course, you will also need to define the Color class by importing it.

Place this above your main class:
Java:

import java.awt.Color;
user23




PostPosted: Sun Dec 11, 2011 12:59 am   Post subject: 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




PostPosted: Sun Dec 11, 2011 1:07 am   Post subject: RE:How can I pass through the color variable?

Well I guess it wasn't for lack of trying.

Java:

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.
Display posts from previous:   
   Index -> Programming, Java -> Java Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 6 Posts ]
Jump to:   


Style:  
Search: