• 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:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

Graphics2D questions

 
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok, I have 2 questions.
The first, and more urgent of the two, is: is it possible to draw transparency onto a graphics object? Like setting the color to a transparent value and then proceeding to draw with that value as you would with a normal color.
The second is: is it possible to compare colors? For instance:
Color colorA = new Color( 255, 255, 255 );
Color colorB = Color.white;
if ( colorA == colorB ) { //it works
}
I have tried a similar comparision and i can't get it to work.
Thank you!
 
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Nick,
for the first, try
Color colr=new Color(Color.white); // or any color
colr.BITMASK=0.0;
g.setColor(colr); // where g is the Graphics object

for the second, u have to compare like this :
if(colorA.equals(colorB)){
}
// don't do what u have done. that compares the instances, which will be never true, even though they have same content.

rgds,
Shashi
btw, i haven't tried out thr first one myself, its just a guess
 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Nick,
Regarding transparency question, I tried something in the alpha value of the constructor to create Color:
I list my findings if it helps you :
This is an applet. You need to use appletviewer.
Code for applet

Code for html

To see the change that alpha value makes you alter the applet code line 19 as
from
c = new Color(0,0,255,20);
to
c = new Color(0,0,255); and see the result.
I hope I did not answer something you did not ask.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic