import javafx.animation.KeyFrame;
import javafx.animation.KeyValue;
import javafx.animation.RotateTransition;
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.Rectangle;
import javafx.stage.Stage;
import javafx.util.Duration;
public class RotateTest extends Application {
private Pane root = new Pane();
private Rectangle rectangle_RotateTransition = new Rectangle(300,300,40,40);
private Rectangle rectangle_TimeLine = new Rectangle(100,100,40,40);
public static void main(String[] args) {
launch(args);
}
@Override
public void start(Stage primaryStage) {
rectangle_RotateTransition.setFill(Color.ORANGE);
root.getChildren().add(rectangle_RotateTransition);
RotateTransition rotateTransition = new RotateTransition(Duration.seconds(2), rectangle_RotateTransition);
rotateTransition.setFromAngle(0);
rotateTransition.setToAngle(360);
// 无限循环
rotateTransition.setCycleCount(Timeline.INDEFINITE);
// 每次旋转后是否改变旋转方向
rotateTransition.setAutoReverse(false);
// RotateTransition旋转方式两轮旋转间有间隔
rotateTransition.play();
Timeline timeline = new Timeline();
double i = Integer.MAX_VALUE;
// 持续68.096年
timeline.getKeyFrames().addAll(new KeyFrame(new Duration(0), new KeyValue(rectangle_TimeLine.rotateProperty(), 0)), new KeyFrame(new Duration(1000*i), new KeyValue(rectangle_TimeLine.rotateProperty(), 360*i)));
root.getChildren().add(rectangle_TimeLine);
// Timeline旋转方式旋转没有间隔
timeline.play();
root.setPrefSize(600, 600);
primaryStage.setResizable(false);
primaryStage.setScene(new Scene(root));
primaryStage.show();
}
}