diff --git a/millions/pom.xml b/millions/pom.xml index bd65466..9981974 100644 --- a/millions/pom.xml +++ b/millions/pom.xml @@ -46,6 +46,9 @@ org.openjfx javafx-maven-plugin 0.0.8 + + no.ntnu.gruppe53.App + org.apache.maven.plugins diff --git a/millions/src/main/java/no/ntnu/gruppe53/App.java b/millions/src/main/java/no/ntnu/gruppe53/App.java index 4205122..a446d34 100644 --- a/millions/src/main/java/no/ntnu/gruppe53/App.java +++ b/millions/src/main/java/no/ntnu/gruppe53/App.java @@ -1,10 +1,25 @@ package no.ntnu.gruppe53; -/** - * Hello world! - */ -public class App { +import javafx.application.Application; +import javafx.stage.Stage; +import no.ntnu.gruppe53.controller.ViewController; +import no.ntnu.gruppe53.views.StartView; + + +public class App extends Application { + @Override + public void start(Stage stage) { + ViewController vm = new ViewController(stage); + + vm.addView("start", new StartView(vm)); + + vm.switchView("start"); + + stage.setTitle("Millions - the Stock Game"); + stage.show(); + } + public static void main(String[] args) { - System.out.println("Hello World!"); + launch(); } } diff --git a/millions/src/main/java/no/ntnu/gruppe53/controller/ViewController.java b/millions/src/main/java/no/ntnu/gruppe53/controller/ViewController.java new file mode 100644 index 0000000..f33de22 --- /dev/null +++ b/millions/src/main/java/no/ntnu/gruppe53/controller/ViewController.java @@ -0,0 +1,61 @@ +package no.ntnu.gruppe53.controller; + +import javafx.scene.Parent; +import javafx.scene.Scene; +import javafx.stage.Stage; + +import java.util.HashMap; +import java.util.Map; + +/** + * Manages application views and handles switching between them. + *

+ * Stores a mapping of view names to JavaFX {@link Parent} nodes and updates + * the current Scene by replacing its root node when switching views. + *

+ */ +public class ViewController { + /** Primary application window used to display the Scene. */ + private Stage stage; + /** Scene containing the currently active view. */ + private Scene scene; + /** Map of view identifiers to their corresponding UI roots. */ + private Map views = new HashMap<>(); + + /** + * Constructs a ViewController and initializes a new Scene. + * + * @param stage the primary application stage where the scene will be set + */ + public ViewController(Stage stage) { + this.stage = stage; + this.scene = new Scene(new javafx.scene.layout.StackPane(), 800, 600); + stage.setScene(scene); + } + + /** + * Registers a view in the controller. + * + * @param name unique identifier used to reference the view later + * @param view the JavaFX root node representing the view + */ + public void addView(String name, Parent view) { + views.put(name, view); + } + + /** + * Switches the currently displayed view by replacing the Scene root. + * + * @param name the identifier of the view to display + * @throws IllegalArgumentException if no view is registered under the given name + */ + public void switchView(String name) { + Parent view = views.get(name); + + if (view == null) { + throw new IllegalArgumentException("No views found matching: " + name); + } + + scene.setRoot(view); + } +} diff --git a/millions/src/main/java/no/ntnu/gruppe53/views/StartView.java b/millions/src/main/java/no/ntnu/gruppe53/views/StartView.java new file mode 100644 index 0000000..a1215c6 --- /dev/null +++ b/millions/src/main/java/no/ntnu/gruppe53/views/StartView.java @@ -0,0 +1,11 @@ +package no.ntnu.gruppe53.views; + +import javafx.scene.layout.VBox; +import no.ntnu.gruppe53.controller.ViewController; + +public class StartView extends VBox { + + public StartView(ViewController vm) { + + } +} \ No newline at end of file