I would like to ask if is there any way to put vertex at specific point (x,y) at canvas. I would like to start an app with graph already built, however using g.addVertex(1) adds vertex to graph but it is being put at canvas at random points.

有帮助吗?

解决方案

public static class MyVertex  {
    private String name;
    private int vIndex;
    private boolean visited = false;
    private int distance = 0;

    private double x;
    private double y;

    public MyVertex(String name, int vIndex) {
        this.name = name;
        this.vIndex = vIndex;
    }

    public void setX(double x) {
        this.x = x;
    }

    public double getX() {
        return x;
    }

    public void setY(double y) {
        this.y = y;
    }

    public double getY() {
        return y;
    }

    public String getName() {
        return name;
    }

}

Maybe this will help you? I used it for my project, and it works great!

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top