Итак, я хочу создать маятник, используя переход и привязку пути. Я попытался привязать конец линии к центру круга, но когда я делаю это, линия не перемещается. Я также попробовал другой путь перехода для самой линии, но затем он переместился бы из своего центра. Я новичок в java, поэтому я не знаю, как это пройти.Перемещение привязки пути
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import com.sun.javafx.geom.Arc2D;
import javafx.animation.PathTransition;
import javafx.animation.Timeline;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.layout.Pane;
import javafx.scene.paint.Color;
import javafx.scene.shape.Arc;
import javafx.scene.shape.ArcType;
import javafx.scene.shape.Circle;
import javafx.scene.shape.Ellipse;
import javafx.scene.shape.Line;
import javafx.scene.shape.Polygon;
import javafx.scene.shape.StrokeType;
import javafx.stage.Stage;
import javafx.util.Duration;
public class Pendulum extends Application{
@Override
public void start(Stage primaryStage){
Pane root = new Pane();
root.setPrefSize(400,400);
Arc arc = new Arc(200, 200, 105, 75, 0, -180);
arc.setType(ArcType.OPEN);
arc.setStroke(Color.BLACK);
arc.setFill(Color.WHITE);
arc.setStrokeWidth(2);
Circle cir = new Circle(200,275,10);
cir.setFill(Color.BLACK);
Line line = new Line(200,100,200,275);
PathTransition pt = new PathTransition (Duration.millis(2000),arc,cir);
pt.setCycleCount(Timeline.INDEFINITE);
pt.setAutoReverse(true);
pt.play();
line.endXProperty().bind(cir.centerXProperty());
line.endYProperty().bind(cir.centerYProperty());
root.getChildren().addAll(arc,cir,line);
Scene scene = new Scene(root, 400, 400);
primaryStage.setTitle("Hello World!");
primaryStage.setScene(scene);
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
}