From b259ca8ad6ae321b6e4c445a3fb8f8fdbcab1bd4 Mon Sep 17 00:00:00 2001 From: Mat Date: Sun, 30 Apr 2023 13:07:36 +0200 Subject: [PATCH] Clear the method CreateMenu to make a new class with the same role --- .../main/java/school_project/Controller.java | 20 +-------- .../main/java/school_project/MenuAcceuil.java | 44 +++++++++++++++++++ .../java/school_project/MenuLevelDay1.java | 13 +++--- 3 files changed, 53 insertions(+), 24 deletions(-) create mode 100644 app/src/main/java/school_project/MenuAcceuil.java diff --git a/app/src/main/java/school_project/Controller.java b/app/src/main/java/school_project/Controller.java index 00da21d..67028fc 100644 --- a/app/src/main/java/school_project/Controller.java +++ b/app/src/main/java/school_project/Controller.java @@ -64,7 +64,7 @@ public class Controller extends Application { //set up the page stage = primaryStage; stage.setTitle("ROAD TO MASTER YOU"); - Menu = createMenu(); + Level_menu = createLevel_menu(); Level_menu2 = createLevel_Menu2(); @@ -72,25 +72,7 @@ public class Controller extends Application { stage.show(); } - private Scene createMenu(){ - Play = new Button("Play"); - Trophy = new Button("Trophy"); - Select_level = new Button("Select Level"); - Select_level.setOnAction(event -> switchScenes(Level_menu)); - title = new Label("Welcome to road to master you"); - title.setFont(Font.font(20)); - title.setTextFill(Color.GOLD); - BdP = new BorderPane(null,title,Select_level,Trophy,Play); - Menu = new Scene(BdP,700,400); - BorderPane.setAlignment(title,Pos.CENTER); - BorderPane.setAlignment(Play,Pos.CENTER); - BorderPane.setAlignment(Select_level,Pos.CENTER); - BorderPane.setAlignment(Trophy,Pos.CENTER); - //Menu.getStylesheets().add("style.css"); todo creat a file css - BdP.setPadding(new Insets(20,60,20,60)); - return Menu; - } private Scene createLevel_menu(){ bck_menu = new Button("Back to the menu"); bck_menu.setOnAction(event -> switchScenes(Menu)); diff --git a/app/src/main/java/school_project/MenuAcceuil.java b/app/src/main/java/school_project/MenuAcceuil.java new file mode 100644 index 0000000..8f4f743 --- /dev/null +++ b/app/src/main/java/school_project/MenuAcceuil.java @@ -0,0 +1,44 @@ +package school_project; + +import javafx.geometry.Insets; +import javafx.geometry.Pos; +import javafx.scene.Scene; +import javafx.scene.control.Button; +import javafx.scene.control.Label; +import javafx.scene.layout.BorderPane; +import javafx.scene.layout.GridPane; +import javafx.scene.paint.Color; +import javafx.scene.text.Font; +import javafx.stage.Stage; + +public class MenuAcceuil extends GridPane { + private Button Play; + private Button SelectLevel; + private Button Trophy; + private Scene scene; + private BorderPane BdP; + private Label Title; + + + public MenuAcceuil(){ + super(); + Play = new Button("Play"); + SelectLevel= new Button("Select Level"); + Trophy = new Button("Trophy"); + Title = new Label("Welcome to Road to Master"); + BdP = new BorderPane(null,Title,SelectLevel,Trophy,Play); + scene = new Scene(BdP,700,400); + Title.setFont(Font.font(20)); + Title.setTextFill(Color.GOLD); + BorderPane.setAlignment(Title, Pos.CENTER); + BorderPane.setAlignment(Play,Pos.CENTER); + BorderPane.setAlignment(SelectLevel,Pos.CENTER); + BorderPane.setAlignment(Trophy,Pos.CENTER); + //Menu.getStylesheets().add("style.css"); todo creat a file css + BdP.setPadding(new Insets(20,60,20,60)); + + } + + + +} diff --git a/app/src/main/java/school_project/MenuLevelDay1.java b/app/src/main/java/school_project/MenuLevelDay1.java index f5ae6a1..00c7d52 100644 --- a/app/src/main/java/school_project/MenuLevelDay1.java +++ b/app/src/main/java/school_project/MenuLevelDay1.java @@ -9,17 +9,16 @@ import javafx.scene.control.Button; import javafx.scene.layout.ColumnConstraints; import javafx.scene.layout.GridPane; -public class MenuLevelDay1 extends Scene { +public class MenuLevelDay1 extends GridPane { //set up all object for the scene private Button[] Level_button = new Button[13]; //set up the scene private Scene Level_menu; private GridPane GdP; - public MenuLevelDay1 (Parent root, int width, int height){ - super(root,width,height); - GridPane GdP = new GridPane(); - Level_menu = new Scene(GdP,700,400); + public MenuLevelDay1 (){ + super(); + GdP = new GridPane(); //add all the button for level Level_button[0] = new Button("1"); Level_button[1] = new Button("2"); @@ -49,6 +48,10 @@ public class MenuLevelDay1 extends Scene { GdP.add(Level_button[9],1,4); GdP.add(Level_button[12],2,4); + + + + } }