Saturday, June 18, 2016

40. FadeTransition

A circle is animated over 10 cycles.


It goes goes 0.5 opacity to 1 opacity and back and forth, with a time of 2 seconds between each transition.


package ex40;
 
import javafx.animation.FadeTransition;
import javafx.application.Application;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.paint.Color;
import javafx.scene.shape.Circle;
import javafx.stage.Stage;
import javafx.util.Duration;
 
public class Ex40 extends Application {
 
    @Override
    public void start(Stage primaryStage) {
 
        Circle circle = new Circle(100,100,50,Color.MIDNIGHTBLUE);
        
        Duration dur = Duration.seconds(2.0);
        FadeTransition fade = new FadeTransition(dur, circle);
        fade.setFromValue(0.5);
        fade.setToValue(1);
        fade.setCycleCount(10);
        fade.setAutoReverse(true);
        fade.play();
                        
        Group root = new Group(circle);
        Scene scene = new Scene(root, 400, 400);
        
        primaryStage.setTitle("Example 40. FadeTransition");
        primaryStage.setScene(scene);
        primaryStage.show();
    }
 
    public static void main(String[] args) {
        launch(args);
    }
}

This is the output at a certain time:


No comments:

Post a Comment