Table of contents
1.
Introduction
2.
JavaFX Sequential Transition
2.1.
Properties
2.2.
Constructors
3.
Example
4.
Frequently Asked Questions
4.1.
What is JavaFX?
4.2.
What are the three life cycle methods of the JavaFX application?
4.3.
What is parallel transition in Java?
5.
Conclusion
Last Updated: Mar 27, 2024

JavaFX Sequential Transition

Author Shivam Sinha
0 upvote
Career growth poll
Do you think IIT Guwahati certified course can help you in your career?

Introduction

JavaFX Fade Transition plays a list of animations in sequential order. This transitions children's inherent node if their node property is not specified. We will see its property, a few constructors, and example in the coming sections.

JavaFX Sequential Transition

This transition applies the animation list on the node in a sequential sequence (one by one). Sequential transition is essential to designing a game that animates its entities in sequential order.

In JavaFX, the javafx.animation.SequentialTransition class is used to represent consecutive transitions. We need to forward a list of multiple transition objects to the constructor of this class. These animations will be applied to the node in sequence (in the order they are passed into the constructor).

Properties

The class contains only one property which is described below:

properties-table

 

Constructors

There are four constructors in the class.

  1. Public SequentialTransition() : It creates an instance of SequentialTransition with the default parameters.
     
  2. Public SequentialTransition(Animation? children): It creates an instance of SequentialTransition with the list of animations.
     
  3. Public SequentialTransition(Node node): It creates an instance of sequential transition with a specified node onto which the sequential transition will be applied.
     
  4. Public SequentialTransition(Node node, Animation? children): It creates an instance of SequentialTransition with the specified node and the list of animations. 

Example

import javafx.animation.PauseTransition;
import javafx.animation.ScaleTransition;
import javafx.animation.SequentialTransition;
import javafx.animation.TranslateTransition;
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;



public class AnimationUI extends Application {  
       
       @Override  
    public void start(Stage stage) throws Exception 
    { 
   
    Rectangle newcir = new Rectangle(140,140,100,100);     
    newcir.setStroke(Color.BLUE);  
    newcir.setFill(Color.RED);  
    newcir.setStrokeWidth(20);  
          
       Duration dur1 = Duration.millis(1000);  
         
            PauseTransition pause = new PauseTransition(Duration.millis(5000));  
           
           TranslateTransition translate = new TranslateTransition(dur1);  
           translate.setByX(500);  
           
           translate.setDuration(Duration.millis(7000));  
             
           translate.setCycleCount(500);  
             
           translate.setAutoReverse(true);  
             
         ScaleTransition scale = new ScaleTransition(dur1);  
         scale.setByX(1.5f);
         scale.setByY(1.5f);
         scale.setAutoReverse(true);
  
         SequentialTransition seqT = new SequentialTransition (newcir,scale, pause, translate);  
         seqT.play();  
       
        Group root = new Group();  
        root.getChildren().addAll(newcir);  
         Scene scene = new Scene(root,500,450);  
         stage.setScene(scene);  
        stage.setTitle("JavaFx Sequential Transition example");  
         stage.show();  
     }
      
    public static void main(String[] args) {  
        launch(args);  
    }  
}


Output:

In order to create a consistent Transition to JavaFX, we must import all required libraries such as javafx.animation.ScaleTransition, javafx.animation.SequentialTransition, javafx.animation.TranslateTransition, javafx.animation.PauseTxans.PauseTrans. scene.Group, javafx.scene.Scene, javafx.scene.paint.Color, javafx.scene.shape.Rectangle, javafx.stage.Stage, javafx.util.Duration.

Then we created a single class called AnimationUI which expands the Application class. Also, we must provide the first method to provide useful details. This method creates the Stage object as the primaryStage. In order for the container to capture the sequence change in a given rectangle, a Group object is created and transferred to a Group stage object.

The Rectangle is created with the help of a builder and a red and color parameter to be completed with a blue stroke. A Sequential Transition object is built, and using sets; various structures are set. It will then display a series of rectangular transformations that are a combination of scale and translation conversion.

The stage is set, the title is set, and the show method () is called the output display. To use the application, the start method (args) is called the main method (). Output A container-like structure is also displayed with the heading, "example of JavaFX Sequential Transition." Also, it shows a rectangle full of red and blue ascending shapes, and then, after a pause, the Rectangle translates from one place to another.

 

output-image1

output-image2

 

Frequently Asked Questions

What is JavaFX?

JavaFX is a set of graphics and media packages that enables developers to design, create, test, debug, and deploy rich client applications that operate consistently across diverse platforms.

What are the three life cycle methods of the JavaFX application?

These are the three life cycles of the JavaFX application:

public void init()

public abstract void start(Stage primaryStage)

public void stop()

What is parallel transition in Java?

The transition that applies multiple animations on a node in parallel.

Conclusion

This article discusses what JavaFX Sequential Transition is, What its properties are. We have also seen a few constructors and understood it using a simple example.

To learn more, see Basics of C++ with Data StructureDBMSOperating System by Coding Ninjas, and keep practicing on our platform Coding Ninjas Studio.

If you think you are ready for the tech giants company, check out the mock test series on code studio.

You can also refer to our Guided Path on Coding Ninjas Studio to upskill yourself in domains like Data Structures and AlgorithmsCompetitive ProgrammingAptitude, and many more!. You can also prepare for tech giants companies like Amazon, Microsoft, Uber, etc., by looking for the questions asked by them in recent interviews. If you want to prepare for placements, refer to the interview bundle. If you are nervous about your interviews, you can see interview experiences to get ideas about these companies' questions.

Do upvote if you find this blog helpful!

Be a Ninja

Happy Coding!

thankyou-image coding ninjas

 

Live masterclass