Animation in JavaFX


Animation in JavaFX:

________________________________________________

import javafx.animation.ScaleTransition;

import javafx.application.Application;

import javafx.geometry.Pos;

import javafx.scene.Scene;

import javafx.scene.image.Image;

import javafx.scene.image.ImageView;

import javafx.scene.layout.HBox;

import javafx.stage.Stage;

import javafx.util.Duration;


public class JavFXAnimation extends Application {

private Image img = new Image("Location of your image//");

@Override

public void start(Stage stage) {

HBox hBox = new HBox(10);

hBox.setAlignment(Pos.CENTER);

ImageView imgV = new ImageView(img);

imgV.setFitHeight(50);

imgV.setFitWidth(50);

hBox.getChildren().add(imgV);

ScaleTransition scale = new ScaleTransition();

scale.setNode(imgV);

scale.setByX(2.5);

scale.setByY(2.5);

scale.setAutoReverse(true);

scale.setCycleCount(250);

scale.setDuration(Duration.millis(1000));

scale.play();

Scene scene = new Scene(hBox, 250, 250);

stage.setTitle("JavaFX Animation");

stage.setScene(scene);

stage.show();

}

public static void main(String[] args) {

Application.launch(args);

}


}

_____________________________________________

Dark Hers

https://darkhers.blogspot.com

YouTube

https://youtube.com/@darkhers

Instagram

https://instagram.com/darkhers

Facebook

https://www.facebook.com/darkhers

TikTok

https://www.tiktok.com/@darkhers

Pinterest

https://www.pinterest.co.uk/darkhers

Twitter

https://twitter.com/Dark_Hers

Comments

Popular Posts