i have a small program that simply displays a jpg and i want it to draw a "point" when the mouse is first clicked. Then a second point when the mouse is clicked again and then also draws a line between them.
I will also want to be able to move theses points once they have been painted. What do i use??
I have been looking at Points2D but i dont understand how to initialze them.
Points2D p = new Points2D() wont work. I think ideally i will have to enter each mouse click into an array but how do i do that?
You could use the MouseListener interface, it allows you to define the methods:
Invoked when the mouse has been clicked on a component.
Invoked when the mouse enters a component.
Invoked when the mouse exits a component.
Invoked when a mouse button has been pressed on a component.
Invoked when a mouse button has been released on a component.
and when the user clicks, call you need to do is to do some coding within the mouseClicked() method.
What i would do is set a variable when the user clicks it increment it by 1, and simply draw the dot where the mouse clicks (do this by using the event parameter passed into the mouseClicked method "e" and getting the x and y coords) enter the clicked points into a vector and call repaint, then in the paint method go through the array and draw the points.
The reason i said to have a variable is so that when the user clicks, you check the variable to see if it is even, if it is even then call a method to draw a line between the last 2 entries in the vector.
As for moving the points, i really cant help ya there...
A kram a day keeps the doctor......guessing
-- Android Development Center
-- Cloud Development Project Center
-- HTML5 Development Center
-- Windows Mobile Development Center