title: Adding a Timer in JavaFX Application for Fade Out Animation
body: <p>I understand this may be a duplicate post. I will link what I've been looking as some of the sources may be wrong for this specific project.</p>
  <p>Long story short, I'm making a game and just switched from JavaSwing to JavaFX. Currently right now, I'm making the start screen and making an attempt to try and make the screen fade out and clear itself out for the game to start. Using <code>VBox</code> and <code>HBox</code>, everything seems to be working <em>kind of</em>.</p>
  <pre><code>    public static void fadeOut() {
          FadeTransition ft = new FadeTransition(Duration.millis(3000), vb);
          ft.setFromValue(1);
          ft.setToValue(0);
          ft.play();
          
          Timer t = new Timer();
          t.schedule(new TimerTask() {
              @Override 
              public void run() {
                  Ce.console.getChildren().clear();
              }
          }, 300l);
          
          
          startTrue();
      }
  </code></pre>
  <p>As of right now, the start screen fades away but doesn't clear itself from the main <code>VBox</code> and assuming I set up <code>Timer()</code> wrong, I get this error.</p>
  <pre><code>Exception in thread &quot;Timer-0&quot; java.lang.IllegalStateException: Not on FX application thread; currentThread = Timer-0
      at javafx.graphics@18.0.1/com.sun.javafx.tk.Toolkit.checkFxUserThread(Toolkit.java:297)
      at javafx.graphics@18.0.1/com.sun.javafx.tk.quantum.QuantumToolkit.checkFxUserThread(QuantumToolkit.java:458)
      at javafx.graphics@18.0.1/javafx.scene.Parent$3.onProposedChange(Parent.java:474)
      at javafx.base@18.0.1/com.sun.javafx.collections.VetoableListDecorator.clear(VetoableListDecorator.java:293)
      at FXConsole/application.console.SS$1.run(SS.java:100)
      at java.base/java.util.TimerThread.mainLoop(Timer.java:566)
      at java.base/java.util.TimerThread.run(Timer.java:516)
  </code></pre>
  <p>I'm thinking that I'm supposed to be using an <code>AnimationTimer()</code>/<code>Timeline()</code> with <code>KeyFrame()</code> but I'm not sure. I'll give it more testing and see if I can come to a solution but if anyone knows a better way to approach this, the help would be greatly appreciated.</p>
  <p>edit: Here was the main page I used for this - <a href="https://stackoverflow.com/questions/4044726/how-to-set-a-timer-in-java">How to set a Timer in Java?</a></p>
  <p>sorry for the inconvenience.</p>