Home > Archive > Java Help > November 2005 > Strange graphics problem
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 |
Strange graphics problem
|
|
| Thanasis \(sch\) 2005-11-23, 7:58 am |
| Hi to all,
i describe a drawArrow method below, which takes 5 parameters : a graphics
object g and the coordinates of 2 points.
What i want to achieve is to draw a dotted line
whenever i pass a Graphics2D object to drawArrow method and a solid line
whenever
i pass a Graphics object.The problem is that even if i pass a
graphics object to drawArrow method i get a dotted line.
Why does this happen?
thanasis
> ========================================
=======
> public void drawArrow(Graphics g, int x1, int y1, int x2, int y2){
>
> if ( g instanceof Graphics2D ){
>
> Graphics2D g2=(Graphics2D)g;
> g2.setStroke (new BasicStroke(1f,BasicStroke.CAP_ROUND,
> BasicStroke.JOIN_ROUND,1f,new float[] {5f, 7f }, 0f));
> }
> g.drawLine(x1,y1,x2,y2);
> }//end of method
> ========================================
=========
| |
| Ingo R. Homann 2005-11-23, 7:58 am |
| Hi,
Thanasis (sch) wrote:
> Hi to all,
>
> i describe a drawArrow method below, which takes 5 parameters : a graphics
> object g and the coordinates of 2 points.
> What i want to achieve is to draw a dotted line
> whenever i pass a Graphics2D object to drawArrow method and a solid line
> whenever
> i pass a Graphics object.The problem is that even if i pass a
> graphics object to drawArrow method i get a dotted line.
Unbelievalbe, expecially since setStroke is a method of Graphics2D and
not Graphics!
Note that instanceof checks the dynamic type of an object, not the
static type:
Object o=new String("");
System.out.println(o instamceof String);
....will print "true".
Similarly, when calling ...
Graphics g=...
draw(g);
....it's possible that 'g' is of type Graphics2D.
Ciao,
Ingo
|
|
|
|
|