From aa6647761470f9547dc81c1571150b30fc837781 Mon Sep 17 00:00:00 2001 From: Jay Trinh <100442532+trinhlong1303@users.noreply.github.com> Date: Wed, 4 May 2022 01:19:45 -0500 Subject: [PATCH] Create JayTrinh_Fading Animation --- JayTrinh_Fading Animation | 51 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 JayTrinh_Fading Animation diff --git a/JayTrinh_Fading Animation b/JayTrinh_Fading Animation new file mode 100644 index 0000000..9757f50 --- /dev/null +++ b/JayTrinh_Fading Animation @@ -0,0 +1,51 @@ +import javafx.animation.AnimationTimer; +import javafx.application.Application; +import javafx.scene.Scene; +import javafx.scene.control.Label; +import javafx.scene.layout.StackPane; +import javafx.scene.text.Font; +import javafx.stage.Stage; + +public class FadingAnimationTest extends Application { + private double opacity = 1; + public Label label; + + public void start (Stage mainstage) { + initializeUI(mainstage); + } + + private void initializeUI (Stage mainstage) { + StackPane root = new StackPane(); + //Animation changes the property of this label control + label= new Label("Object1 Testing"); + label.setFont(Font.font(28)); + root.getChildren().add(label); + + //Create AnimationTimer method + AnimationTimer timer = new MainObjTimer(); + timer.start(); + Scene scene = new Scene(root, 300, 250); + mainstage.setTitle("Animation Timer Test for Main Object"); + mainstage.setScene(scene); + mainstage.show(); + } + + private class MainObjTimer extends AnimationTimer { + public void handle(long a) { + doHandle(); + } + + private void doHandle() { + opacity -= 0.003; + label.opacityProperty().set(opacity); + + if (opacity <=0) { + stop(); + System.out.println("Animation ended"); + } + } + } + public static void main(String[] args) { + launch(args); + } +}