简体   繁体   English

java.awt.geom.Point2D.createArray()

[英]java.awt.geom.Point2D.createArray()

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

Exception in thread "main" java.lang.NoSuchMethodError: java.awt.geom.Point2D.createArray () [Ljava / awt / geom / Point2D $ Double; 线程“主”中的异常java.lang.NoSuchMethodError:java.awt.geom.Point2D.createArray()[Ljava / awt / geom / Point2D $ Double; at MainClass.main (MainClass.java:20) 在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);


        }

//class Point2D package java.awt.geom; // Class 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;
    }
}

Your createArray() doesn't take parameters. 您的createArray()不接受参数。 You're calling it with two. 您用两个来称呼它。 Hence the error. 因此,错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM