strange behaviour Line2D

J

joe pribele

For some reason you can't change the location of the points in a line
directly. Yes I know there are methods in Line2D to set the location
but they take both Points and I was being lazy and only wanted to
change one.

I doesn't say anywhere in the docs that the points are read only.

Here is a short app that demonstrate the problem.

import java.awt.geom.*;

public class Test {

public static void main(String[] args ) {
Line2D.Float f = new Line2D.Float( 10,10,5,55 );
System.out.println( "p1=" + f.getP1() );
System.out.println( "p2=" + f.getP2() ); // 5, 55
f.getP2().setLocation( 66,66 );
System.out.println( "p2=" + f.getP2() ); // 5, 55 not 66,66 as
expected
}
}
 
D

David Vivash

Look at the docs. The points are stored as public floats (x1, y1, x2, y2),
so there's no way you'd be able to do what you are trying.

You can do "f.x2 = 66; f.y2 = 66;" to set the co-ordinates of the second
point directly.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,566
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top