使用多段线连接圆JavaFX

使用多段线连接圆JavaFX,javafx,polyline,Javafx,Polyline,我已经在JavaFX中的图形上创建了圆,我想用多段线连接这些圆。有人知道这样做的语法吗?谢谢 使用,e。g、 APolyline可能会起作用,但如果您使用,可以更轻松地执行此操作,因为这允许您访问。可以使用绑定将线点的位置绑定到圆的位置。这样,即使稍后移动圆,线也将保持在适当的位置 例子 private static void bindLinePosTo(Circle circle, LineTo lineTo) { lineTo.xProperty().bind(circle.cen

我已经在JavaFX中的图形上创建了圆,我想用多段线连接这些圆。有人知道这样做的语法吗?谢谢

使用,e。g、

A
Polyline
可能会起作用,但如果您使用,可以更轻松地执行此操作,因为这允许您访问。可以使用绑定将线点的位置绑定到圆的位置。这样,即使稍后移动圆,线也将保持在适当的位置

例子
private static void bindLinePosTo(Circle circle, LineTo lineTo) {
    lineTo.xProperty().bind(circle.centerXProperty());
    lineTo.yProperty().bind(circle.centerYProperty());
}

private static void animate(Circle circle, Duration duration, double dy) {
    Timeline animation = new Timeline(
            new KeyFrame(Duration.ZERO, new KeyValue(circle.centerYProperty(), circle.getCenterY())),
            new KeyFrame(duration, new KeyValue(circle.centerYProperty(), circle.getCenterY()+dy)));
    animation.setAutoReverse(true);
    animation.setCycleCount(Animation.INDEFINITE);
    animation.play();
}

@Override
public void start(Stage primaryStage) {
    MoveTo start = new MoveTo();
    LineTo line1 = new LineTo();
    LineTo line2 = new LineTo();

    Circle c1 = new Circle(10, 100, 5);
    Circle c2 = new Circle(50, 100, 5);
    Circle c3 = new Circle(100, 100, 5);

    c1.setFill(Color.RED);
    c2.setFill(Color.RED);
    c3.setFill(Color.RED);

    start.xProperty().bind(c1.centerXProperty());
    start.yProperty().bind(c1.centerYProperty());
    bindLinePosTo(c2, line1);
    bindLinePosTo(c3, line2);

    Path path = new Path(start, line1, line2);

    Pane root = new Pane(path, c1, c2, c3);

    animate(c1, Duration.seconds(1), 100);
    animate(c2, Duration.seconds(2), 50);
    animate(c3, Duration.seconds(0.5), 150);

    Scene scene = new Scene(root, 110, 300);
    primaryStage.setScene(scene);
    primaryStage.show();
}