1818
1919public class DinosaurMenu extends FXGLMenu {
2020
21- public DinosaurMenu () throws FileNotFoundException {
21+ public DinosaurMenu () {
2222 super (MenuType .MAIN_MENU );
2323
2424 Media media = new Media (getClass ().getResource (GameConstants .MAINMENU_SOUND ).toExternalForm ());
@@ -31,59 +31,66 @@ public DinosaurMenu() throws FileNotFoundException {
3131 var title = FXGL .getUIFactoryService ().newText (GameConstants .GAME_NAME , Color .LIME , FontType .MONO , 35 );
3232 var startButton = new Button ("Start Game" );
3333 var quitButton = new Button ("Quit" );
34- FileInputStream fileInputStream = new FileInputStream ("../dinosaur-exploder/src/main/resources/assets/textures/dinomenu.png" );
35- FileInputStream mutemusic_button =new FileInputStream ("../dinosaur-exploder/src/main/resources/assets/textures/silent.png" );
36-
37- // image for dino in main menu
38- Image image = new Image (fileInputStream );
39- ImageView imageView = new ImageView (image );
40- imageView .setFitHeight (250 );
41- imageView .setFitWidth (200 );
42- imageView .setX (200 );
43- imageView .setY (190 );
44- imageView .setPreserveRatio (true );
45-
46- //adding image to manually mute music
47-
48- Image mute = new Image (mutemusic_button );
49- ImageView imageView_mute =new ImageView (mute );
50- imageView_mute .setFitHeight (40 );
51- imageView_mute .setFitWidth (50 );
52- imageView_mute .setX (490 );
53- imageView_mute .setY (20 );
54- imageView_mute .setPreserveRatio (true );
55-
56- startButton .setMinSize (50 , 50 );
57- quitButton .setMinSize (140 , 50 );
58-
59- title .setTranslateY (100 );
60- title .setTranslateX (getAppWidth () / 2 - 145 );
61-
62- startButton .setTranslateY (400 );
63- startButton .setTranslateX (getAppWidth () / 2 - 50 );
64- startButton .setStyle ("-fx-font-size:20" );
65-
66- quitButton .setTranslateY (500 );
67- quitButton .setTranslateX (getAppWidth () / 2 - 50 );
68- quitButton .setStyle ("-fx-font-size:20" );
69-
70- startButton .setOnAction (event -> {
71- fireNewGame ();
72- mainMenuSound .stop ();
73- });
74-
75- imageView_mute .setOnMouseClicked (mouseEvent -> {
76- mainMenuSound .stop ();
77- });
78-
79- imageView_mute .setOnMousePressed (mouseEvent -> {
80- mainMenuSound .stop ();
81- });
82- quitButton .setOnAction (event -> fireExit ());
83-
84- getContentRoot ().getChildren ().addAll (
85- bg , title , startButton , quitButton ,imageView ,imageView_mute
86- );
34+ try {
35+
36+
37+ FileInputStream fileInputStream = new FileInputStream ("../dinosaur-exploder/src/main/resources/assets/textures/dinomenu.png" );
38+ FileInputStream mutemusic_button = new FileInputStream ("../dinosaur-exploder/src/main/resources/assets/textures/silent.png" );
39+
40+ // image for dino in main menu
41+ Image image = new Image (fileInputStream );
42+ ImageView imageView = new ImageView (image );
43+ imageView .setFitHeight (250 );
44+ imageView .setFitWidth (200 );
45+ imageView .setX (200 );
46+ imageView .setY (190 );
47+ imageView .setPreserveRatio (true );
48+
49+ //adding image to manually mute music
50+
51+ Image mute = new Image (mutemusic_button );
52+ ImageView imageView_mute = new ImageView (mute );
53+ imageView_mute .setFitHeight (40 );
54+ imageView_mute .setFitWidth (50 );
55+ imageView_mute .setX (490 );
56+ imageView_mute .setY (20 );
57+ imageView_mute .setPreserveRatio (true );
58+
59+ startButton .setMinSize (50 , 50 );
60+ quitButton .setMinSize (140 , 50 );
61+
62+ title .setTranslateY (100 );
63+ title .setTranslateX (getAppWidth () / 2 - 145 );
64+
65+ startButton .setTranslateY (400 );
66+ startButton .setTranslateX (getAppWidth () / 2 - 50 );
67+ startButton .setStyle ("-fx-font-size:20" );
68+
69+ quitButton .setTranslateY (500 );
70+ quitButton .setTranslateX (getAppWidth () / 2 - 50 );
71+ quitButton .setStyle ("-fx-font-size:20" );
72+
73+ startButton .setOnAction (event -> {
74+ fireNewGame ();
75+ mainMenuSound .stop ();
76+ });
77+
78+ imageView_mute .setOnMouseClicked (mouseEvent -> {
79+ mainMenuSound .stop ();
80+ });
81+
82+ imageView_mute .setOnMousePressed (mouseEvent -> {
83+ mainMenuSound .stop ();
84+ });
85+ quitButton .setOnAction (event -> fireExit ());
86+
87+ getContentRoot ().getChildren ().addAll (
88+ bg , title , startButton , quitButton , imageView , imageView_mute
89+ );
90+ }
91+ catch (FileNotFoundException e ){
92+ System .out .println ("File not found" + e .getMessage ());
93+ }
8794 }
8895
8996}
0 commit comments