×

JavaFX Parallel Transition

In the JavaFX application, in order to generate the parallel transition, we have to apply parallel transition on any particular shape. It has the ability to execute multiple transactions parallelly. All methods needed for this purpose are present in the javafx.animation.ParallelTransition class.

JavaFX Animation - Parallel Transition

Example:

import javafx.animation.Interpolator;
import javafx.animation.ParallelTransition;
import javafx.animation.Transition;
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 AnimationUI extends Application {  


    @Override  
    public void start(Stage stage) throws Exception 
    { 
    
            Circle newball1 = new Circle(0,0,20);
            newball1.setFill(Color.RED);
            Circle newball2 = new Circle(0,0,20);
            newball2.setFill(Color.BLUE);
            
            Group root = new Group();
            root.getChildren().addAll(newball1, newball2);
            Scene scene = new Scene(root, 600, 600);
            stage.setScene(scene);
            stage.setTitle("Javafx Parallel transition example");
            stage.show(); 
            
            TranslateTransition newt1 = new TranslateTransition(
            Duration.millis(2000), newball1);
            newt1.setFromX(newball1.getRadius());
            newt1.setToX(scene.getWidth() - newball1.getRadius());
            newt1.setFromY(scene.getHeight() / 3);
            newt1.setToY(scene.getHeight() / 3);
            newt1.setCycleCount(Transition.INDEFINITE);
            newt1.setAutoReverse(true);
            newt1.setInterpolator(Interpolator.LINEAR);


            
            TranslateTransition newt2 = new TranslateTransition(
                Duration.millis(2000), newball2);
            newt2.setFromX(scene.getWidth() - newball2.getRadius());
            newt2.setToX(newball2.getRadius());
            newt2.setFromY(scene.getHeight() / 3 * 2);
            newt2.setToY(scene.getHeight() / 3 * 2);
            newt2.setCycleCount(Transition.INDEFINITE);
            newt2.setAutoReverse(true);
            newt2.setInterpolator(Interpolator.LINEAR);


            
            ParallelTransition pt = new ParallelTransition(newt1, newt2);
            pt.play();
            
            
     }
      
    public static void main(String[] args) {  
        launch(args);  
    }  
}

Output:

In order to create the parallel Transition in JavaFX, we have to import all the required libraries such as javafx.animation.TranslateTransition, javafx.animation.ParallelTransition, javafx.animation.PauseTransition, 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 have created one class named AnimationUI extending the Application class. Also, we have to override the start method to provide implementation details. This method creates an object of Stage as primaryStage. For the container to hold a parallel transition on balls, a Group object is created which is then passed to the Scene class object.

The circle is created with the help of the constructor and the size parameter and red and blue color to be filled are passed in it. A Parallel Transition object is created and using setters various properties are set. Then it will show parallel transitions on circle shaped balls.

The stage is prepared, the title is set and the show() method is called to display output. In order to run the application, the launch(args) method is called in the main() method. In output Frame like container is displayed with the title, " JavaFX Parallel Transition Example”. Also, it displays one red and one blue ball translating from one place to another simultaneously.

JavaFX Animation - Parallel Transition JavaFX Animation - Parallel Transition

JavaFX Animation - Parallel Transition

Example:

import javafx.animation.FadeTransition;
import javafx.animation.ParallelTransition;
import javafx.animation.ScaleTransition;
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 SliderUI 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);  
         
           
           FadeTransition fade = new FadeTransition();  
           
           
           fade.setDuration(Duration.millis(3000));  
             
           fade.setFromValue(10);  
           fade.setToValue(0.1);  
             
           fade.setCycleCount(1000);  


             


         
         ScaleTransition scale = new ScaleTransition(dur1);  
         scale.setByX(1.5f);
         scale.setByY(1.5f);
         scale.setAutoReverse(true);




           
         ParallelTransition seqT = new ParallelTransition (newcir,scale, fade);  
           
         seqT.play();  
       
        Group root = new Group();  
        root.getChildren().addAll(newcir);  
         Scene scene = new Scene(root,500,450);  
         stage.setScene(scene);  
        stage.setTitle("JavaFx Parallel Transition example");  
         stage.show();  
     }
      
    public static void main(String[] args) {  
        launch(args);  
    }  
}

Output:

In order to create the parallel Transition in JavaFX, we have to import all the required libraries such as javafx.animation.ScaleTransition, javafx.animation.ParallelTransition, javafx.animation.FadeTransition, javafx.application.Application, javafx.scene.Group, javafx.scene.Scene, javafx.scene.paint.Color, javafx.scene.shape.Rectangle, javafx.stage.Stage, javafx.util.Duration.

Then we have created one class named AnimationUI extending the Application class. Also, we have to override the start method to provide implementation details. This method creates an object of Stage as primaryStage. For the container to hold a parallel transition on the rectangle, a Group object is created which is then passed to the Scene class object.

The rectangle is created with the help of the constructor and the size parameter and red color to be filled are passed in it. A Parallel Transition object is created and using setters various properties are set. Then it will show parallel transitions on the rectangle.

The stage is prepared, the title is set and the show() method is called to display output. In order to run the application, the launch(args) method is called in the main() method. In output Frame like container is displayed with the title, " JavaFX Parallel Transition Example”. Also, it displays one rectangle scaling and fading simultaneously.

JavaFX Animation - Parallel Transition

Related Topics

JavaFX TextField

In the JavaFX application, to get the user information as input from the user, a form is created using textfields which allows the user to enter input for specific fields....

4 minutes read.

JavaFX Rotate Transition

In the JavaFX application, in order to generate the rotate transition, we have to apply rotation transition on any particular shape. It has the ability to rotate the shape along...

4 minutes read.

JavaFX Scatter Chart

In the JavaFX application, in order to create Scatter Chart, the ScatterChart class is used. The Scatter Chart allows us to plot data along the x and y axis of...

4 minutes read.

JavaFX Event Handling

JavaFX gives way to handle various events in web application, desktop applications and graphical applications. In the JavaFX application, in order to allow user to interact with application various events...

4 minutes read.

JavaFX Scaling

In the JavaFX application, in order to apply various Scaling effects, we use this class. It has the ability to change the size of the given object. All methods needed...

5 minutes read.

JavaFX Polygon

In the JavaFX application, in order to draw a polygon, the Polygon class is used. The Polygon allows us to join any number of points in the space. All methods...

4 minutes read.

JavaFX RadioButton

In the JavaFX application, to get the user information in the form of choice from the user, a form is created using radio buttons that allow the user to select...

3 minutes read.

JavaFX File Chooser

In the JavaFX application, in order to open or save the file, FileChooser is used. It allows user to choose the file from system location and save it in a...

4 minutes read.

JavaFX Fade Transition

In the JavaFX application, in order to generate the fade transition, we have to apply fade transition on any particular shape. It has the ability to show the fading colors...

4 minutes read.

JavaFX Rotation

In the JavaFX application, in order to apply various rotation effects, we use this class. It has the ability to rotate the given object. It rotates the given node along...

3 minutes read.

JavaFX Gaussian Blur

In the JavaFX application, in order to apply various Gaussian blur effect, we use GaussianBlur class. It has the ability to apply blur effect on the given object. All methods...

4 minutes read.

JavaFX HyperLink

In the JavaFX application, in order to access and use webpages, hyperlinks are used. In HTML anchor tags are used in the same way in JavaFX hyperlinks are used. To...

4 minutes read.

JavaFX Drop Shadow

In the JavaFX application, in order to apply various Drop Shadow effect, we use this class. It has the ability to create the drop shadow of the given object. This...

4 minutes read.

JavaFX Cylinder

In the JavaFX application, in order to draw a Cylinder, the Cylinder class is used. The Cylinder allows us to form a 3D shape having rectangular faces and a straight...

4 minutes read.

JavaFX - Basic Structure of Application

Every JavaFX application is mainly divided into three main components namely Scene, Stage, and nodes. For using these components we need to import javafx.application.Application class in every javafx application. Life...

4 minutes read.

JavaFX ID selector

In the JavaFX application, in order to apply various css effect using the id selector, we use the various css classes available in the JavaFX. This is generally used to...

4 minutes read.

JavaFX Pie Chart

In the JavaFX application, in order to create Pie Chart, the PieChart class is used. The Pie Chart allows us to plot data along with the sectors of the circle....

3 minutes read.

JavaFX BorderPane

In the JavaFX application, in order to set Border Pane as a layout, the BorderPane class is used. The BorderPane layout allows us to arrange the components in the left,...

4 minutes read.

JavaFX Inner Shadow

In the JavaFX application, in order to apply various Inner Shadow effect, we use this class. It has the ability to create the inner shadow of the given object. This...

4 minutes read.

JavaFX Glow

In the JavaFX application, in order to apply various glow effect, we use Glow class. It has the ability to glow the colors of the shape. All methods needed for...

4 minutes read.