Well, Class.getName() will include the full package name, so it won't
just return Graphics2D, it will return java.awt.Graphics2D.  You're
probably better off just using "if (g instanceof Graphics2D)".

But then I'm not really sure why you need to structure the code the
way you do below.  The code in your else clause is much more
straightforward, so I'm not sure why you can't just use that code
regardless of whether it's a Graphics or Graphics2D.

Chris

On Nov 22, 2005, at 3:02 PM, Thanasis (Hotmail) wrote:
Hi to all,

i call the method drawArrow  that  i describe  below.When i pass as
argument
a Graphics object  i want my program to draw a GREEN arrow.
However when i  pass as argument a Graphics2D object  i want my
program to
draw a RED arrow.
The problem is that i am always getting a GREEN arrow.Why does this
happen?What
===========================================================
public void drawArrow(Graphics g, int x1, int y1, int x2, int y2){


if (g.getClass().getName().equals("Graphics2D"))   { // graphics2d
object

Graphics2D g2=(Graphics2D)g;

   g2.draw(new Line2D.Double(x1,y1,x2,y2));

   GeneralPath arrow = new GeneralPath();
   arrow.moveTo(xValues[0],yValues[0]);
   arrow.lineTo(xValues[1],yValues[1]);
   arrow.lineTo(xValues[2],yValues[2]);
   arrow.lineTo(xValues[0],yValues[0]);

   g2.setColor(Color.red);

   g2.fill(arrow);

}
else                                       // graphics object
{
   g.drawLine(x1,y1,x2,y2);
   g.setColor(Color.green);
  g.fillPolygon(xValues,yValues,3);
}

}

======================================================================
=====
To unsubscribe, send email to [EMAIL PROTECTED] and include in
the body
of the message "signoff JAVA2D-INTEREST".  For general help, send
email to
[EMAIL PROTECTED] and include in the body of the message "help".

===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff JAVA2D-INTEREST".  For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".

Reply via email to