translate Transition in JavaFX - Java JavaFX

Java examples for JavaFX:Animation

Description

translate Transition in JavaFX

Demo Code


    //package com.java2s;

    import javafx.animation.SequentialTransition;
    import javafx.animation.SequentialTransitionBuilder;
    import javafx.animation.TranslateTransition;
    import javafx.event.ActionEvent;

    import javafx.scene.image.Image;
    import javafx.scene.image.ImageView;

    import javafx.util.Duration;

    public class Main {
        public static SequentialTransition translateTransition(final ImageView iv, final Image img, int fromX, int toY) {
    TranslateTransition translateOutTransition
            = new TranslateTransition(Duration.seconds(0.4), iv);
    translateOutTransition.setFromX(fromX);
    translateOutTransition.setToX(toY);/* w  w  w. ja v a  2s .  co  m*/
    translateOutTransition.setOnFinished((ActionEvent arg0) -> {
        iv.setImage(img);
    });
        
    TranslateTransition translateInTransition
            = new TranslateTransition(Duration.seconds(0.4), iv);
    translateInTransition.setFromX(toY);
    translateInTransition.setToX(fromX);
    SequentialTransition sequentialTransition
            = SequentialTransitionBuilder
            .create()
            .children(translateOutTransition, translateInTransition)
            .build();

    return sequentialTransition;
}
    }

Related Tutorials