/home/caleb/ASDV-Java/Semester 3/Assignments/lab3_CalebFontenot/src/lab3_calebfontenot/BallControl.java |
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;
public class BallControl extends Application {
@Override
public void start(Stage primaryStage) throws Exception {
BouncingBall bouncingBall = new BouncingBall();
Scene scene = new Scene(bouncingBall, 800, 600);
primaryStage.setTitle("Bouncing Ball Control");
primaryStage.setScene(scene);
primaryStage.show();
bouncingBall.requestFocus();
bouncingBall.setOnMousePressed(new EventHandler<MouseEvent>() {
@Override
public void handle(MouseEvent event) {
bouncingBall.pause();
}
});
bouncingBall.setOnMouseReleased(e
-> {
bouncingBall.play();
});
bouncingBall.setOnKeyPressed (e
-> {
if (e.getCode() == KeyCode.UP) {
bouncingBall.increaseSpeed();
} else if (e.getCode() == KeyCode.DOWN) {
bouncingBall.decreaseSpeed();
}
}
);
}
public static void main(String[] args) {
launch(args);
}
}