Check for range: if-statement

Hi,

I declare a point, e.g.

private Point2D goToThisPoint =new Point2D.Double(100, 100);

and I am storing the mouse clicks in a variable:

private Point2D currentMouseClickPosition;

I would like to display a JOptionPane if the mouse click is within a range of 10px in relation to my goToThisPoint. My only problem is that I don't know how to check for this range...

Thanks!!!

[518 byte] By [SFLa] at [2007-11-27 8:54:57]
# 1
Point2D has various distance(...) methods you can use: http://java.sun.com/j2se/1.4.2/docs/api/java/awt/geom/Point2D.html
prometheuzza at 2007-7-12 21:15:10 > top of Java-index,Java Essentials,Java Programming...
# 2
Since the coordinates of the Point2D are in pixels, you can apply the cartesian distance formula to the two points to find out their distance in pixels. http://en.wikipedia.org/wiki/Distance_formula
hunter9000a at 2007-7-12 21:15:10 > top of Java-index,Java Essentials,Java Programming...
# 3
Thanks, I am now usingpublic double distance(Point2D pt)from java.awt.geom.Point2D :)
SFLa at 2007-7-12 21:15:10 > top of Java-index,Java Essentials,Java Programming...
# 4
> Thanks, I am now using>> public double distance(Point2D pt)>> from java.awt.geom.Point2D :)You're welcome. It wouldn't hurt to read the link Mr Hunter posted as well: you might brush up your math skills a bit!; )
prometheuzza at 2007-7-12 21:15:10 > top of Java-index,Java Essentials,Java Programming...