Skip to content

25 start page #34

Merged
merged 3 commits into from
Apr 24, 2026
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion millions/src/main/java/no/ntnu/gruppe53/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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");
Expand Down
Original file line number Diff line number Diff line change
@@ -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);
}
}
39 changes: 39 additions & 0 deletions millions/src/main/java/no/ntnu/gruppe53/views/StartView.java
Original file line number Diff line number Diff line change
@@ -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());
}
}