With RotateTransition we can rotate a node.
Here the button is rotated for 20 seconds, from 0 to 45 degree, and another 20 seconds, going back.
package ex64;
import javafx.animation.RotateTransition;
import javafx.application.Application;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.paint.Color;
import javafx.stage.Stage;
import javafx.util.Duration;
public class Ex64 extends Application {
@Override
public void start(Stage stage) {
Group root = new Group();
Button button = new Button("RotateTransition");
button.setPrefSize(250,250);
button.setLayoutX(100); button.setLayoutY(100);
RotateTransition rt = new RotateTransition(
Duration.seconds(20), button);
rt.setToAngle(45);
rt.setFromAngle(0);
rt.setAutoReverse(true);
rt.setCycleCount(2);
root.getChildren().add(button);
button.setOnAction(e -> rt.play());
Scene scene = new Scene(root, 500, 500, Color.PAPAYAWHIP);
stage.setTitle("Example 64. RotateTransition");
stage.setScene(scene);
stage.show();
}
public static void main(String[] args) {
launch();
}
}
This is the output during the animation:
No comments:
Post a Comment