For Programmers: Free Programming Magazines  


Home > Archive > Java Help > January 2006 > Setting Color using RGB values









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Setting Color using RGB values
fb

2006-01-25, 4:14 am

Hello,

I usually set the colour of my things (like setpaint and whatnot) by
doing something like g2D.setPaint(Color.magenta) (assuming g2D is a
Graphics 2D object etc.) but I would really like to customize my
colours. So I was thinking that setting the RGB colours individually
would be a good way to go about this. I did this all the time in my
assembler days, but Java is a far cry from that. I noticed that there
is a way to do this using a Color class (I think that was it), but I
can't seem to get it to work. I tried g2D.setpaint(Color(15,128,134));
but that didn't work (and I kinda knew it wouldn't) so I was wondering
how to go about this...

ttyl,

--
"Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are, by
definition, not smart enough to debug it." --Brian Kernighan
IchBin

2006-01-25, 4:14 am

fb wrote:
> Hello,
>
> I usually set the colour of my things (like setpaint and whatnot) by
> doing something like g2D.setPaint(Color.magenta) (assuming g2D is a
> Graphics 2D object etc.) but I would really like to customize my
> colours. So I was thinking that setting the RGB colours individually
> would be a good way to go about this. I did this all the time in my
> assembler days, but Java is a far cry from that. I noticed that there
> is a way to do this using a Color class (I think that was it), but I
> can't seem to get it to work. I tried g2D.setpaint(Color(15,128,134));
> but that didn't work (and I kinda knew it wouldn't) so I was wondering
> how to go about this...
>
> ttyl,
>

Did you try..

g2D.setpaint(new Color(red, green, blue));

--

Thanks in Advance...
IchBin, Pocono Lake, Pa, USA
http://weconsultants.servebeer.com/JHackerAppManager
________________________________________
__________________________________

'If there is one, Knowledge is the "Fountain of Youth"'
-William E. Taylor, Regular Guy (1952-)
Oliver Wong

2006-01-25, 7:16 pm


"IchBin" <weconsul@ptd.net> wrote in message
news:l-mcnZKOr8OmiUreUSdV9g@ptd.net...
> fb wrote:
> Did you try..
>
> g2D.setpaint(new Color(red, green, blue));


You could also create local references to color objects to reuse them.

Color red = new Color(255,0,0);
Color darkRed = new Color(128,0,0);
g2d.setPaint(red);

etc.

- Oliver


IchBin

2006-01-25, 7:16 pm

Oliver Wong wrote:
> "IchBin" <weconsul@ptd.net> wrote in message
> news:l-mcnZKOr8OmiUreUSdV9g@ptd.net...
>
> You could also create local references to color objects to reuse them.
>
> Color red = new Color(255,0,0);
> Color darkRed = new Color(128,0,0);
> g2d.setPaint(red);
>
> etc.
>
> - Oliver
>
>

It was late in the morning from the night before. I meant top say..

g2D.setpaint(new Color(15,128,134))



--

Thanks in Advance...
IchBin, Pocono Lake, Pa, USA
http://weconsultants.servebeer.com/JHackerAppManager
________________________________________
__________________________________

'If there is one, Knowledge is the "Fountain of Youth"'
-William E. Taylor, Regular Guy (1952-)
Remi Arntzen

2006-01-26, 4:00 am


fb wrote:
> Hello,
>
> I usually set the colour of my things (like setpaint and whatnot) by
> doing something like g2D.setPaint(Color.magenta) [...] I tried
> g2D.setpaint([new ]Color(15,128,134));
> but that didn't work


In what way did it not work?

Hal Rosser

2006-01-26, 7:06 pm

try putting new in front of the word Color.


Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com