gpt4 book ai didi

java.awt.geom.Point2D.createArray()

转载 作者:行者123 更新时间:2023-12-01 09:36:35 25 4
gpt4 key购买 nike

Hi I want to initialize an array of Point2D (Point2D.Double [])
Somehow I fail, I get the following error:

线程“main”中出现异常 java.lang.NoSuchMethodError: java.awt.geom.Point2D.createArray() [Ljava/awt/geom/Point2D$Double; 在 MainClass.main (MainClass.java:20)

***The purpose of the program:***
In the main there to produce an array of length 10,000 may be incorporated into the data structures and another 100,000 long array of points that will be submitted once the data structure to return the closest point.
I would like to build two data structures and move them all the points and make sure I get every time the same result in both.

import java.awt.Component;
import java.awt.List;
import java.awt.geom.Point2D;
import java.awt.geom.Point2D.Double;
import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Vector;

public class MainClass {
private static final int N = 10000;
static Vector<Point2D> coords = new Vector<Point2D>();
static Point2D newCoords;
Point2D oldCoords;



public static void main(String[] args) {
final long startTime = System.nanoTime();
Point2D.Double[] points=Point2D.createArray();

in this line i get the error.

        static void setDisplayParams(Vector<Point2D> coords, double xMin, double xMax, double yMin, double yMax){
Point2D newCoords, oldCoords;
Vector<Point2D> displayCoords = new Vector<Point2D>();
for (int i=0; i<coords.size(); ++i){
oldCoords=coords.elementAt(i);
newCoords=coords.elementAt(i);
// newCoords.setLocation(oldCoords.getDoublePointVarX(), yMax-oldCoords.getDoublePointVarY());
displayCoords.add(newCoords);
displayParams.displayCoords.add(new Point2D.Double(newCoords.getX(), yMax-newCoords.getY()));
}

//here i check the duration of the RunTime program

            final long duration = System.nanoTime() - startTime;
System.out.println(duration);


}

//类Point2D 包java.awt.geom;

public class Point2D implements Comparable<Point2D> {
public class Double extends Point2D {



//****************************************** Variables ******************************************************

private double x;
private double y;

//****************************************** Constructor *************************************************
public Double(double x, double y) {
super(x, y);

}
//****************************************** Getters & Setters *************************************************
public double getX() {
return x;
}
public void setX(double x) {
this.x = x;
}
public double getY() {
return y;
}
public void setY(double y) {
this.y = y;
}

}
private double y;
private double x;


public Point2D(double x, double y) {
this.x = x;
this.y = y;
}


//****************************************** Other Methods *************************************************
public double distanceTo(Point2D that) {
double dx = this.x - that.x;
double dy = this.y - that.y;
return Math.sqrt(dx*dx + dy*dy);
}

check the distance between to points.

    public int compareTo(Point2D p, Point2D q) {
double dist1 = distanceTo(p);
double dist2 = distanceTo(q);
if (dist1 < dist2) return -1;
else if (dist1 > dist2) return +1;
else return 0;
}
@Override
public int compareTo(Point2D o) {
return 0;
}


public static Point2D.Double[] createArray(){
Point2D.Double[] points = new Point2D.Double[10000];
for (int i = 0; i < 10000; ++i) {
double x = Math.random();
double y = Math.random();
points[i]=(Double) new Point2D(x, y);
}
return points;
}
}

最佳答案

您的createArray()不带参数。你用两个来调用它。因此出现错误。

关于java.awt.geom.Point2D.createArray(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38848654/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com