I'm starting to enjoy JavaFX ^.^

This commit is contained in:
2023-08-26 02:09:47 -05:00
parent 986aa47cec
commit 82ccc27d9f
529 changed files with 6552 additions and 20 deletions

View File

@@ -7,6 +7,7 @@ package lab3_calebfontenot;
import javafx.application.Application;
import javafx.event.EventHandler;
import javafx.scene.Scene;
import javafx.scene.input.KeyCode;
import javafx.scene.input.MouseEvent;
import javafx.stage.Stage;
@@ -17,8 +18,7 @@ import javafx.stage.Stage;
public class BallControl extends Application {
@Override
public void start(Stage primaryStage) throws Exception
{
public void start(Stage primaryStage) throws Exception {
BouncingBall bouncingBall = new BouncingBall();
// Create a scene and place it in the stage
Scene scene = new Scene(bouncingBall, 800, 600);
@@ -26,32 +26,35 @@ public class BallControl extends Application {
primaryStage.setScene(scene);
primaryStage.show();
bouncingBall.requestFocus();
bouncingBall.setOnMousePressed(new EventHandler<MouseEvent>() {
@Override
public void handle(MouseEvent event)
{
public void handle(MouseEvent event) {
bouncingBall.pause();
}
});
bouncingBall.setOnMouseReleased(e ->
{
bouncingBall.setOnMouseReleased(e
-> {
bouncingBall.play();
});
}
// Increase and decrease animation
bouncingBall.setOnKeyPressed(e ->
{
if (e.getCode() == KeyCode.UP) {
bouncingBall.setOnKeyPressed (e
-> {
if (e.getCode() == KeyCode.UP) {
bouncingBall.increaseSpeed();
} else if (e.getCode() == KeyCode.DOWN) {
bouncingBall.decreaseSpeed();
}
});
public static void main(String[] args)
{
}
);
}
public static void main(String[] args) {
launch(args);
}
}

View File

@@ -71,10 +71,12 @@ public void pause() {
public void increaseSpeed() {
animation.setRate(animation.getRate() * 1.5);
System.out.println(animation.getRate());
}
public void decreaseSpeed() {
animation.setRate(animation.getRate() * 1.5 > 0 ? animation.getRate() / 1.5 : 0);
System.out.println(animation.getRate());
}
public DoubleProperty rateProperty() {