Created
January 15, 2019 05:16
-
-
Save nsilvestri/ddc756394ca66c90dc017ce103e9791c to your computer and use it in GitHub Desktop.
JavaFX Stage Animation Demo: Automatically Moving Windows
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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