I'll elaborate a bit more than some of the other responses. See below.
the code I used to create the list is here:
ArrayList my_list = new ArrayList();
...
public void mouseDragged(MouseEvent evt) {
test_point.x = evt.getX();
test_point.y = evt.getY();
my_list.add(test_point);
System.out.println( test_point.x );
System.out.println( test_point.y );
}
As everyone suspected, there is only *one* object of class point2D in
your code. You presumably create it at the beginning, and you keep
changing its properties. To provide a commonly useful metaphor, think
of objects as balloons, and references (like the variable test_point) as
ribbons that you use to hold on to the balloons. When you add an object
to a collection, you're essentially tying a new ribbon to the balloon,
so that the balloon is attached to the collection.
What you're doing is creating one balloon. Every time the mouse is
dragged, you are erasing the numbers you had written on this balloon and
replacing them with new numbers, and then tying another ribbon from this
*one* balloon to the collection. In the end, you still only have one
balloon, and what's written on it is the last set of numbers you wrote
(since you've erased everything else).
You do have a whole lot of ribbons tied to that one balloon, though.
When you ask the collection for its contents, it will hand you those
ribbons one by one; and each time you get a ribbon, you're going to
following it to the balloon it's attached to and read what's written on
that balloon. But since all the ribbons are attached to the same
balloon, you're seeing the same thing every time you do that.
Now, what you really want to do is, each time the mouse is dragged, blow
up a new balloon, write the new numbers on it, and tie a new ribbon from
the collection to that new balloon. To do that, you need to actually
create a new balloon, which you do with the "new" keyword.
test_point = new point2D();
test_point.x = evt.getX();
test_point.y = evt.getY();
Now you've written the information on a new balloon, which can be added
to the collection to make things work as you like.
--
www.designacourse.com
The Easiest Way to Train Anyone... Anywhere.
Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation