• Post Reply Bookmark Topic Watch Topic
  • New Topic

Graphics2D questions  RSS feed

 
Nick Howell
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • 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!
 
Shashi Kanta
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
  • 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
 
Pradyumna Hari
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • 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.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!