Do you think IIT Guwahati certified course can help you in your career?
No
Introduction
In order to generate the translate Transition in the JavaFX application, we must apply the translate transition on any specific shape. It has the ability to translate the shape in all the three-axis. We will see its property, a few constructors, and example in the coming sections.
JavaFX Translate Transition
It translates a node from one position to another over a specified time. There is a continuous change in the properties of translateX and translateY of the node for transition at regular intervals. The speed of transition depends on the number of cycles the transition will have at a specified time. In JavaFX, TranslateTransition is represented by the JavaFX.animation.TranslateTransition class. We have to instantiate this class in order to apply an appropriate Translate Transition on an object.
Properties
The properties of the class are given below in the table.
Constructors
There are three constructors in the class.
Public TranslateTransition() : It creates the new instance of TranslateTransition with the default parameters.
Public TranslateTransition(Duration duration): It creates a new instance of TranslateTransition with the specified duration.
Public TranslateTransition(Duration duration, Node node): It creates the new instance of Translate Transition with the specified duration and node.
Example
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.Circle;
import javafx.stage.Stage;
import javafx.util.Duration;
public class SliderUI extends Application {
@Override
public void start(Stage primaryStage) throws Exception
{
Circle cir = new Circle(50,100,50);
cir.setFill(Color.BLUE);
cir.setStroke(Color.RED);
TranslateTransition translate = new TranslateTransition();
translate.setByX(500);
translate.setDuration(Duration.millis(7000));
translate.setCycleCount(500);
translate.setAutoReverse(true);
translate.setNode(cir);
translate.play();
Group root = new Group();
root.getChildren().addAll(cir);
Scene scene = new Scene(root,500,200);
primaryStage.setScene(scene);
primaryStage.setTitle("JavaFX Translate Transition example");
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
}
Output:
To create Translate Transition to JavaFX, we must import all required libraries such as javafx.animation.TranslateTransition, javafx.application.Application, javafx.scene.Group, javafx.scene.Scene, javafx.scene.paint. Color, javafx.scene.shape.Circle, javafx.stage.Stage, javafx.util.Duration. Then we created a single class called AnimationUI which extends the Application class. Also, we must override the start method to provide implementation details. This method creates the Stage object as the primaryStage. In order for the container to hold the translation circle, a Group object is created and transferred to the scene class object.
The circle is created with the help of the size parameters and the constructor. The stage is set, the title is set, and the show method () is called the output display. To launch the application, the start method (args) is called the main () method. Output A container-like structure is also displayed with the heading, "example JavaFX Translate Transition." Also, it shows a circle full of blue that translates into a certain plane.
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 a streamer in JavaFx?
The streamer is open source media engine for JavaFX.
Conclusion
This article discusses what JavaFX Translate Transition is, What its properties are. We have also seen a few constructors and understood JavaFX Translate Transition using a simple example.
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.