• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

changing colors in an if statement

 
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello
I want to change the color of the shapes in my code to something more fun but it isn't working. I would like to use web safe colors such as FF3300 or something to that effect. I know I need to do sonmething like .setColor(new Color(0xFF,0x33,ox00)); etc etc but it (the color stays red when I did it to the last current shape. Any suggestions?

Thanks
Rob
 
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Try this:
public void midAction()
{
// This method changes the color of the currently focused shape
// from blue to red, red to green, and green to blue
Color currentColor;
currentColor = currentShape.getColor();
if(currentColor.equals(Color.green) currentShape.setColor(Color.blue);
else if(currentColor.equals(Color.red) currentShape.setColor(Color.green);
else if(currentColor.equals(Color.blue) currentShape.setColor(Color.red);
// Repaint the window to show the change
win.repaint();
}
Cheers
JohnB
 
Rob Michaelson
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Oh I think what I needed to say is that I want to REPLACE blue,green,red with a web safe color to make it more intersting but its not working
Rob
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, 0xff, 0x33, 0x00 is going to be very similar to Color.red, which is 0xff, 0x00, 0x00; they may look identical to you. Why not try something more significantly different while you're testing? 0xff, 0x33, 0xff is purply pink, for instance.
 
Rob Michaelson
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Right - I will pick the colors later but syntactically I want to get it correct
Rob
 
Rob Michaelson
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here's the problem - any suggestions?

I can't (or don't know how) to change "==Color.blue" to a web safe color for this to work
the
 
Jaunty John
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think this is what you are looking for???
The values, (0, 51, 255) are integer values representing the rgb values
JohnB
//~ Formatted by jFormat�2003 EMail: jlbalder@netscape.net 2003.07.24
...previous code
public void midAction() {
// This method changes the color of the currently focused shape
// from blue to red, red to green, and green to blue
Color currentColor;
Color ROSE = new Color(255, 0, 51);//Colors NOT accurate!
Color FROG = new Color(0, 255, 51);
Color NAVY = new Color(0, 51, 255);
currentColor = currentShape.getColor();
if(currentColor.equals(Color.green)) currentShape.setColor(NAVY);
else if(currentColor.equals(Color.red)) currentShape.setColor(FROG);
else if(currentColor.equals(Color.blue)) currentShape.setColor(ROSE);
// Repaint the window to show the change
win.repaint();
}//~public void midAction()...
more code...
 
Rob Michaelson
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey
Thanks Jaunty - I will try that shortly-- I appreciate it!
Rob
 
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Moving this to the Swing / JFC / AWT forum...
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic