-
Notifications
You must be signed in to change notification settings - Fork 34
/
Copy pathMain.java
83 lines (77 loc) · 2.94 KB
/
Main.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
package com.example.javafxproject.CarGame;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.Alert;
import javafx.scene.control.Button;
import javafx.scene.control.ButtonType;
import javafx.scene.image.Image;
import javafx.scene.input.KeyCode;
import javafx.scene.paint.Color;
import javafx.stage.Stage;
//import java.awt.event.KeyEvent;
public class Main extends Application {
public static void main(String... args) {
launch();
}
@Override
public void start(Stage stage) throws Exception {
FXMLLoader loader = new FXMLLoader(getClass().getResource("/CarGame.fxml"));
Parent root = loader.load();
Controller controller = loader.getController();
Scene scene = new Scene(root);
stage.getIcons().add(new Image("/gameLogo.jpeg"));
stage.setTitle("My Car Game");
stage.setScene(scene);
// stage.setFullScreen(true);
stage.setResizable(false);
// scene.setOnKeyPressed(event ->{
// //scene.setFill(Color.BLACK);
// switch(event.getCode()){
// case KeyCode.UP :
// controller.increasingSpeed(event);
// break;
// case KeyCode.DOWN:
// controller.decreaseSpeed(event);
// break;
// case KeyCode.LEFT:
// controller.left(event);
// break;
// case KeyCode.RIGHT:
// controller.right(event);
// break;
// case KeyCode.ESCAPE:
// controller.stopEverything();
// Alert alert = new Alert(Alert.AlertType.CONFIRMATION);
// alert.setTitle("Exit");
// alert.setContentText("Do you want to Continue");
// ButtonType exit = new ButtonType("Exit");
// ButtonType play = new ButtonType("Continue/Play");
//
// alert.getButtonTypes().setAll(exit,play);
// if(alert.showAndWait().get() == exit){
// stage.close();
// }
// else{
// controller.startAgain();
// }
// }
// });
stage.setOnCloseRequest(event->{
Alert alert = new Alert(Alert.AlertType.CONFIRMATION);
alert.setTitle("Exit Confirmation");
alert.setContentText("Do you want to exit");
controller.stopEverything();
if(alert.showAndWait().get() == ButtonType.OK){
stage.close();
}
else{
event.consume();
controller.startAgain();
}
});
controller.stage = stage;
stage.show();
}
}