diff --git a/millions/src/main/java/no/ntnu/gruppe53/App.java b/millions/src/main/java/no/ntnu/gruppe53/App.java index a446d34..851d613 100644 --- a/millions/src/main/java/no/ntnu/gruppe53/App.java +++ b/millions/src/main/java/no/ntnu/gruppe53/App.java @@ -2,6 +2,7 @@ import javafx.application.Application; import javafx.stage.Stage; +import no.ntnu.gruppe53.controller.StartViewController; import no.ntnu.gruppe53.controller.ViewController; import no.ntnu.gruppe53.views.StartView; @@ -11,8 +12,10 @@ public class App extends Application { public void start(Stage stage) { ViewController vm = new ViewController(stage); - vm.addView("start", new StartView(vm)); + StartView startView = new StartView(vm); + new StartViewController(startView, vm); + vm.addView("start", startView); vm.switchView("start"); stage.setTitle("Millions - the Stock Game"); diff --git a/millions/src/main/java/no/ntnu/gruppe53/controller/StartViewController.java b/millions/src/main/java/no/ntnu/gruppe53/controller/StartViewController.java new file mode 100644 index 0000000..48bf965 --- /dev/null +++ b/millions/src/main/java/no/ntnu/gruppe53/controller/StartViewController.java @@ -0,0 +1,19 @@ +package no.ntnu.gruppe53.controller; + +import no.ntnu.gruppe53.views.StartView; +import javafx.application.Platform; + +/** + * aaaa + */ +public class StartViewController { + + public StartViewController(StartView view, ViewController vm) { + + view.setOnNewGame(() -> { + System.out.println("Start new game"); + }); + + view.setOnQuit(Platform::exit); + } +} \ No newline at end of file diff --git a/millions/src/main/java/no/ntnu/gruppe53/views/StartView.java b/millions/src/main/java/no/ntnu/gruppe53/views/StartView.java index a1215c6..efbebf3 100644 --- a/millions/src/main/java/no/ntnu/gruppe53/views/StartView.java +++ b/millions/src/main/java/no/ntnu/gruppe53/views/StartView.java @@ -1,11 +1,50 @@ package no.ntnu.gruppe53.views; +import javafx.geometry.Pos; +import javafx.scene.control.Button; import javafx.scene.layout.VBox; +import no.ntnu.gruppe53.controller.StartViewController; import no.ntnu.gruppe53.controller.ViewController; +/** + * Represents the first page seen by the user of the application. + */ public class StartView extends VBox { + private final Button newGameButton; + private final Button quitButton; + /** + * Constructs the view and sets parameters to be exposed for the {@link StartViewController}. + * + * @param vm the {@link ViewController} for the view + */ public StartView(ViewController vm) { + this.setAlignment(Pos.CENTER); + this.setSpacing(20); + newGameButton = new Button("New Game"); + quitButton = new Button("Quit"); + + newGameButton.setPrefWidth(200); + quitButton.setPrefWidth(200); + + this.getChildren().addAll(newGameButton, quitButton); + } + + /** + * Sets the method to be run when + * + * @param action + */ + public void setOnNewGame(Runnable action) { + newGameButton.setOnAction(e -> action.run()); + } + + /** + * + * @param action + */ + public void setOnQuit(Runnable action) { + quitButton.setOnAction(e -> action.run()); } } \ No newline at end of file