title: JavaFX Animation: Move Shape (Star) randomly
body: <p>My problem is, that after every keyframe the x- and y-Position of the rectangle should change by random.
  Right now only when I start the program, the rectangles position is set by random, but not in the animation itself.</p>
  
  <p>How can I do this, thanks a lot...</p>
  
  <pre><code>public class TimeLines extends Application {
  
  private Rectangle rectBasicTimeline;
  private Timeline timeline;
  
  @Override
  public void start(Stage primaryStage) {
      Button btn = new Button();
      btn.setText("Do Animation");
      int x = new Random().nextInt(500);
      int y = new Random().nextInt(400);
      rectBasicTimeline = new Rectangle(x, y, 100, 50);
      rectBasicTimeline.setFill(Color.RED);
  
      btn.setOnAction(new EventHandler&lt;ActionEvent&gt;() {
  
          @Override
          public void handle(ActionEvent event) {
  
              final Timeline timeline = new Timeline();
              timeline.setCycleCount(Timeline.INDEFINITE);
              timeline.setAutoReverse(true);
              final KeyValue kx = new KeyValue(rectBasicTimeline.xProperty(), x + 200);
              final KeyValue ky = new KeyValue(rectBasicTimeline.yProperty(), y + 200);
              final KeyValue kScale = new KeyValue(rectBasicTimeline.scaleXProperty(), 2);
              final KeyValue kFade = new KeyValue(rectBasicTimeline.opacityProperty(), 0);
              final KeyFrame kf = new KeyFrame(Duration.millis(3000), kx, ky, kScale, kFade);
              timeline.getKeyFrames().add(kf);
              timeline.play();
        }
      });
  
      AnchorPane root = new AnchorPane();
      root.getChildren().addAll(btn, rectBasicTimeline);
      Scene scene = new Scene(root, 800, 600);
      primaryStage.setTitle("Hello World!");
      primaryStage.setScene(scene);
      primaryStage.show();
  }
  
  /**
   * @param args the command line arguments
   */
  public static void main(String[] args) {
      launch(args);
  }
  </code></pre>
  
  <p>}</p>