Java:
package geometry;
import main.*;
import javax.swing.*;
import java.awt.Point;
public class PointDistanceCalculator
{
static JFrame f;
public PointDistanceCalculator()
{
String[] toolUsingList = {"one point's distance", "lowest distance of several points", "highest distance of several points"};
int toolUsing = JOptionPane.showOptionDialog(f, "How du you want to use this tool?", "using selection", 0, 3, null, toolUsingList, null);
switch (toolUsing)
{
case 0:
Point p = new Point();
double distance = pointDistance(p);
JOptionPane.showMessageDialog(f, distance, "distance", 1);
case 1:
int pointNumber = Utils.enterInt(f, "Enter the number of points!", "number of points");
Point[] pointList = new Point[pointNumber];
Point min = pointList[0];
for(int i = 0; i <= pointList.length; i++)
{
pointList[i] = newPoint(i + 1);
min = (pointDistance(min) < pointDistance(pointList[i])) ? min : pointList[i];
}
JOptionPane.showMessageDialog(f, min, "lowest distance", 1);
}
}
public static Point newPoint()
{
int xCoordinate = Utils.enterInt(f, "Enter the point's x-coordinate!", "x-coordinate");
if(xCoordinate < 0)
{
Utils.errorMessage(f, "The coordinates have to be positiv.", "coordinate negativ");
newPoint();
}
int yCoordinate = Utils.enterInt(f, "Enter the point's y-coordinate!", "y-coordinate");
if(yCoordinate < 0)
{
Utils.errorMessage(f, "The coordinates have to be positiv.", "coordinate negativ");
newPoint();
}
Point p = new Point(xCoordinate, yCoordinate);
return p;
}
public static Point newPoint(int continuous)
{
int xCoordinate = Utils.enterInt(f, "Enter the point" + continuous + "'s x-coordinate!", "x-coordinate");
if(xCoordinate < 0)
{
Utils.errorMessage(f, "The coordinates have to be positiv.", "coordinate negativ");
newPoint(continuous);
}
int yCoordinate = Utils.enterInt(f, "Enter the point" + continuous + "'s y-coordinate!", "y-coordinate");
if(yCoordinate < 0)
{
Utils.errorMessage(f, "The coordinates have to be positiv.", "coordinate negativ");
newPoint(continuous);
}
Point p = new Point(xCoordinate, yCoordinate);
return p;
}
public static double pointDistance(Point p)
{
double distance = Math.sqrt(p.x * p.x + p.y * p.y);
return distance;
}
}