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.


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 Structure, DBMS, Operating 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 Algorithms, Competitive Programming, Aptitude, 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!
