blob: 93c6868b3baf3d402e63bda6bfe3da3d8cf3bb7e [file] [log] [blame]
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package transitionrotate;
import javafx.animation.RotateTransition;
import javafx.animation.RotateTransitionBuilder;
import javafx.animation.Timeline;
import javafx.application.Application;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.paint.Color;
import javafx.scene.shape.Rectangle;
import javafx.stage.Stage;
import javafx.util.Duration;
/**
* A sample in which a node rotates around its center over a given time.
*
* @related animation/transitions/FadeTransition
* @related animation/transitions/FillTransition
* @related animation/transitions/ParallelTransition
* @related animation/transitions/PathTransition
* @related animation/transitions/PauseTransition
* @related animation/transitions/ScaleTransition
* @related animation/transitions/SequentialTransition
* @related animation/transitions/StrokeTransition
* @related animation/transitions/TranslateTransition
* @see javafx.animation.RotateTransition
* @see javafx.animation.RotateTransitionBuilder
* @see javafx.animation.Transition
*/
public class TransitionRotate extends Application {
private RotateTransition rotateTransition;
private void init(Stage primaryStage) {
Group root = new Group();
primaryStage.setResizable(false);
primaryStage.setScene(new Scene(root, 140,140));
Rectangle rect = new Rectangle(20, 20, 100, 100);
rect.setArcHeight(20);
rect.setArcWidth(20);
rect.setFill(Color.ORANGE);
root.getChildren().add(rect);
rotateTransition = RotateTransitionBuilder.create()
.node(rect)
.duration(Duration.seconds(4))
.fromAngle(0)
.toAngle(720)
.cycleCount(Timeline.INDEFINITE)
.autoReverse(true)
.build();
}
public void play() {
rotateTransition.play();
}
@Override public void stop() {
rotateTransition.stop();
}
@Override public void start(Stage primaryStage) throws Exception {
init(primaryStage);
primaryStage.show();
play();
}
/**
* The main() method is ignored in correctly deployed JavaFX
* application. main() serves only as fallback in case the
* application can not be launched through deployment artifacts,
* e.g., in IDEs with limited FX support. NetBeans ignores main().
* @param args the command line arguments
*/
public static void main(String[] args) {
launch(args);
}
}