JavaFX 在进入下一个方法之前等待动画方法完成

min*_*hah 5 java animation javafx

如何让 JavaFX 等待一个带有动画的方法完成,然后再转到下一个方法?所以我的代码如下:

public void spinWheel(){
        RotateTransition rotation = new 
        rotation.setByAngle(-(720+(15*(i+(24-finalIndex)))));
        rotation.play();
        wheelResult=wheel.spinWheel(i);

spinButton.setOnAction(e->{
    spinButton.setDisable(true);
    wheelGui.spinWheel();
    spinGame();
    });
Run Code Online (Sandbox Code Playgroud)

所以 spinwheel() 方法就是动画。它本质上是一个轮子在旋转。该方法会打印一些代码,并在某些情况下重新激活按钮。然而,这是瞬时的。我希望动画在下一个方法运行之前完成,因为文本很快或按钮再次打开并可以中断操作。

jns*_*jns 4

您可以使用

RotateTransition rotateTransition = new RotateTransition();
rotateTransition.setOnFinished(e -> yourMethod())
rotateTransition.play();
Run Code Online (Sandbox Code Playgroud)