Friday, July 15, 2016

100. Sequential Transition

In SequentialTransition, we can have many animations in sequence.


Here we have a pause of 100 ms, and then two translate animations, one for the top and one for the bottom rectangle.


package ex100;

import javafx.animation.Animation;
import javafx.animation.PauseTransition;
import javafx.animation.SequentialTransition;
import javafx.animation.TranslateTransition;
import javafx.application.Application;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.paint.Color;
import javafx.scene.shape.Rectangle;
import javafx.stage.Stage;
import javafx.util.Duration;

public class Ex100 extends Application {
    
    @Override
    public void start(Stage stage) {
        
        Rectangle rect1 = new Rectangle(50, 50);
        rect1.setFill(Color.RED);
        rect1.setLayoutY(50);
        Rectangle rect2 = new Rectangle(50, 50);
        rect2.setFill(Color.GREEN);
        rect2.setLayoutY(350);
        
        TranslateTransition trans1 = new TranslateTransition();
        trans1.setNode(rect1);
        trans1.setFromX(0);
        trans1.setToX(400);
        trans1.setDuration(Duration.seconds(1));
        
        TranslateTransition trans2 = new TranslateTransition();
        trans2.setNode(rect2);
        trans2.setFromX(0);
        trans2.setToX(400);
        trans2.setDuration(Duration.seconds(2));
        
        SequentialTransition seqTransition = new SequentialTransition();
        seqTransition.setCycleCount(Animation.INDEFINITE);
        seqTransition.setAutoReverse(true);
        seqTransition.getChildren().addAll(
                new PauseTransition(Duration.millis(100)),
                trans1,
                trans2);
        
        Button button = new Button("Start");
        button.setPrefWidth(250);
        button.setOnAction(e -< {
            seqTransition.play();
            button.setVisible(false);
        });
        
        Group root = new Group(rect1, rect2, button); 
        
        Scene scene = new Scene(root, 450, 450, Color.LIGHTSKYBLUE);
        stage.setTitle("Example 100. Sequential Transition");
        
        stage.setScene(scene);
        stage.show();
    }

    public static void main(String[] args) {
        launch();
    }
}


This is the output during the animation:


1 comment:

  1. Jumpert Group's new online gambling firm Jumpert Group
    Jumpert 상주 출장안마 Group's new 영주 출장샵 online gambling firm Jumpert Group's new online gambling firm Jumpert Group announced 충주 출장샵 the launch of its 태백 출장안마 new GVC Capital 여수 출장마사지

    ReplyDelete