title: Set and use variables outside timeline in javafx 8
body: <p>I am trying to writing a javafx app to watch the system clipboard:</p>
  
  <pre><code>package sample;
  
  import javafx.event.ActionEvent;
  import javafx.animation.KeyFrame;
  import javafx.animation.Timeline;
  import javafx.application.Application;
  import javafx.event.EventHandler;
  import javafx.util.Duration;
  import javafx.fxml.FXMLLoader;
  import javafx.scene.Parent;
  import javafx.scene.Scene;
  import javafx.stage.Stage;
  import javafx.scene.control.Button;
  import javafx.scene.layout.StackPane;
  import javafx.scene.input.Clipboard;
  import javafx.scene.input.ClipboardContent;
  
  public class Main extends Application {
  
      @Override
      public void start(Stage primaryStage) throws Exception{
          primaryStage.show();
  
          final Clipboard clipboard = Clipboard.getSystemClipboard();
          final String oldString = "";
          final String newString = "";
          Timeline repeatTask = new Timeline(new KeyFrame(Duration.millis(200), new EventHandler&lt;ActionEvent&gt;() {
  
              @Override
              public void handle(ActionEvent event) {
                  if (clipboard.hasString()) {
                      newString = clipboard.getString();
                      if(oldString != newString) {
                          System.out.printf("String changed in clipboard: " + newString);
                          oldString = newString;
                      }
                      else {
                          System.out.println("String not changed.");
                      }
                  }
              }
          }));
          repeatTask.setCycleCount(Timeline.INDEFINITE);
          repeatTask.play();
      }
  
  
      public static void main(String[] args) {
          launch(args);
      }
  }
  </code></pre>
  
  <p>The problem is I need to store the old content of the clipboard outside the timeline object, and I need to make changes to them, but once they set as final -- as java requires -- modification is no longer possible.</p>