Skip to content

Instantly share code, notes, and snippets.

@bmesuere
Created March 17, 2014 18:55
Show Gist options
  • Save bmesuere/9605866 to your computer and use it in GitHub Desktop.
Save bmesuere/9605866 to your computer and use it in GitHub Desktop.
package animationtest;
import javafx.animation.KeyFrame;
import javafx.animation.KeyValue;
import javafx.animation.Timeline;
import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.layout.StackPane;
import javafx.scene.paint.Color;
import javafx.scene.shape.Rectangle;
import javafx.scene.shape.RectangleBuilder;
import javafx.stage.Stage;
import javafx.util.Duration;
/**
*
* @author Bart Mesuere <Bart.Mesuere@UGent.be>
*/
public class AnimationTest extends Application {
@Override
public void start(Stage primaryStage) {
Rectangle rect = RectangleBuilder.create().width(200).height(200).fill(Color.RED).build();
StackPane root = new StackPane();
root.getChildren().add(rect);
Timeline animation = new Timeline();
animation.getKeyFrames().addAll(
new KeyFrame(new Duration(1000),
new KeyValue(rect.widthProperty(), 100),
new KeyValue(rect.heightProperty(), 100)),
new KeyFrame(new Duration(2000),
new KeyValue(rect.widthProperty(), 300),
new KeyValue(rect.heightProperty(), 300))
);
animation.setOnFinished(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent t) {
Stage stage = new Stage();
StackPane pane = new StackPane();
pane.getChildren().add(new Label("Hello world"));
stage.setScene(new Scene(pane, 100, 100));
stage.showAndWait();
}
});
animation.setCycleCount(1);
Scene scene = new Scene(root, 300, 300);
primaryStage.setScene(scene);
primaryStage.show();
animation.play();
}
/**
* The main() method is ignored in correctly deployed JavaFX application.
* main() serves only as fallback in case the application can not be
* launched through deployment artifacts, e.g., in IDEs with limited FX
* support. NetBeans ignores main().
*
* @param args the command line arguments
*/
public static void main(String[] args) {
launch(args);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment