Trying to change the color of an object depending on if/else statement
Hi, all-
I'm trying to use an if/else statement to determine the color of an object. Here's what the outside method that draws the color looks like, as well as the if/else statement that needs to be able to change the color of the object. The problem is that I need this logic to operate in the opposite direction. I need the SimGraphics method to be called directly in the if/else statement, so that the drawFastRoundRect( Color.whatever ) command works INSIDE that if/else statement. Can I do that? If so, how?
publicvoid draw( SimGraphics g ){
g.drawFastRoundRect( Color.blue );
if (colorMeSurprised ==1){
g.drawFastRoundRect( Color.magenta );
}
elseif (colorMeSurprised == 2){
g.drawFastRoundRect( Color.pink);
}...
for (int i = 0; i < threeNeighborVectors.size(); i++ );
if (surferNeighbors.size() > swimmerNeighbors.size()){
iHaveMoreSurferNeighbors.add(aOcean);
colorMeSurprised = 1;
}
elseif (swimmerNeighbors.size() > surferNeighbors.size()){
iHaveMoreSwimmerNeighbors.add(aOcean);
colorMeSurprised = 2;
}
> so, what exactly is your problem?
Let me repeat it one more time; I need the color to change IN the if/else statement by calling on an outside method. I cannot pass a value from the if/else statement to an outside method; I need it to work the other way around. Please carefully read posts; I get yelled at enough for not reading carefully, so please do your part as well.
> Please carefully read posts; I get yelled at enough for not reading carefully, so please do your part as well.
I've read you question 5 times and still have no idea what you are asking.
> I need the SimGraphics method to be called directly in the if/else statement
SimGraphics isn't a method its a class, so I still don't know what you mean.
Instead of yelling at people trying to help, you should spend more time making understandable questions.
Posting a few lines of random code doesn't give us much information to work with either.
> hi
> what i could make of query is
> u want draw(SimGraphics ) to be called in if -else
> of for
> if that's the case i will help u
Thank God! Do you know how to do that? I've been so frustrated because though I need to call draw(SimGraphics) inside that if/else statement in another method, it's not good code, nor have I been able to take the advice of so many people on this site who have given me good code tips. Since I HAVE to do it this way (it's a class assignment, and hence not something I can work around), I would certainly appreciate any help you can give me.