Skip to content

Instantly share code, notes, and snippets.

@nsilvestri
Created January 15, 2019 05:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nsilvestri/ddc756394ca66c90dc017ce103e9791c to your computer and use it in GitHub Desktop.
Save nsilvestri/ddc756394ca66c90dc017ce103e9791c to your computer and use it in GitHub Desktop.
JavaFX Stage Animation Demo: Automatically Moving Windows
import javafx.animation.AnimationTimer;
import javafx.application.Application;
import javafx.stage.Stage;
public class ConstantRight extends Application {
@Override
public void start(Stage stage) {
stage.show();
stage.setWidth(300);
stage.setHeight(200);
new AnimationTimer() {
int ticks = 0;
@Override
public void handle(long now) {
// Change position of Stage every 1/60th of a second in a sinusoidal path
stage.setX(Math.sin(Math.toDegrees(ticks / 3000.0)) * 600 + 650);
stage.setY(Math.cos(Math.toDegrees(ticks / 1000.0)) * 350 + 350);
ticks++;
}
}.start();
}
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