I'm developing a paint in java and would like to know how to create a function that stores the mouse coordinates of the initial and final mousePressed and mouseReleased. Thanks!
I'm developing a paint in java and would like to know how to create a function that stores the mouse coordinates of the initial and final mousePressed and mouseReleased. Thanks!
A good fireplace would be you create a class where you will have everything you want to save, type Point, Color, format, etc. type:
public class MyPoints
{
Point pointPressed, pointReleased;
// faz o constructor(s)
MyPoints(Point pointPressed,Point pointReleased)
{
this.pointPressed = pointPressed;
this.pointReleased = pointReleased;
}
// faca seus getter(s)
}
You can create an ArrayList of this class,
ArrayList<MyPoints> ar = new ArrayList<>();
Then you can create a MouseAdapter and override the
public void mousePressed(MouseEvent me)
and the
public void mouseReleased(MouseEvent me)
Inside the mousePressed () takes the event and finds the point where it was pressed and within the mouseReleased takes the event, find the point where it was released and use
ar.add(new MyPoints(pointPressed,pointReleased));
Now you have an array with your Points where events occurred