I am trying to calculate the distance I move a mouse within a box, I am using the MouseEvent.getX() and MouseEvent.getY() to calculate the start position of the mouse and then I have another method saving the position and calculating the distance the mouse has moved. Here is some code I wrote to demonstrate this.
BlankArea.addMouseMotionListener(new MouseMotionListener(){
@Override
public void mouseMoved(MouseEvent mm){
System.out.println("Position (" + mm.getX() + ", "
+ mm.getY() + ")");
savePosition(mm.getX(), mm.getY());
}
@Override
public void mouseDragged(MouseEvent md) {
System.out.println("Position (" + mm.getX() + ", "
+ mm.getY() + ")");
savePosition(mm.getX(), mm.getY());
}
});
My Question is: The Java API states that getX() & getY() returns the horizontal & vertical coordinate relative to the source component respectively. What is the source component? What unit is the output coordinate measured in?