Skip to content

Commit

Permalink
feat: adding styling to application + Market page
Browse files Browse the repository at this point in the history
  • Loading branch information
martin committed May 25, 2026
1 parent 08991e1 commit d7c9b06
Show file tree
Hide file tree
Showing 6 changed files with 648 additions and 74 deletions.
24 changes: 18 additions & 6 deletions src/main/java/millions/App.java
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
package millions;


import java.math.BigDecimal;
import java.util.Objects;
import java.util.logging.Level;
import java.util.logging.Logger;

import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Alert;
import javafx.stage.Stage;
import millions.controller.GameController;
import millions.controller.fileIO.CSV.CSVStockFileWriter;
import millions.controller.fileIO.InvalidFormatException;
import millions.controller.fileIO.UncheckedFileNotFoundException;
import millions.view.ExitView;
Expand All @@ -20,6 +18,9 @@
/** Main JavaFX application entry point for the Millions stock trading game. */
public class App extends Application {
private static final Logger logger = Logger.getLogger(App.class.getName());
private static final String STYLESHEET =
Objects.requireNonNull(App.class.getResource("/styles/millions.css")).toExternalForm();

@Override
public void start(Stage stage) {
GameController controller = new GameController();
Expand All @@ -39,23 +40,31 @@ public void start(Stage stage) {
GameView gameView =
new GameView(
controller,
() -> stage.setScene(new Scene(new ExitView(controller.getPlayer()), 400, 250)));
() -> {
ExitView exitView = new ExitView(controller.getPlayer());
exitView.setMaxSize(Double.MAX_VALUE, Double.MAX_VALUE);
Scene exitScene = new Scene(exitView, 500, 400);
exitScene.getStylesheets().add(STYLESHEET);
stage.setScene(exitScene);
});
controller.getPlayer().addListener(gameView);
controller.getExchange().addListener(gameView);

Scene gameScene = new Scene(gameView, 1920, 1080);
gameScene.getStylesheets().add(STYLESHEET);
stage.setScene(gameScene);
} catch (InvalidFormatException e) {
logger.log(Level.WARNING, "InvalidFormatException: " + e.getMessage());

Alert alert = new Alert(Alert.AlertType.ERROR);
alert.setTitle("Error");
alert.setHeaderText("Error with selected file");
alert.setContentText(e.getMessage() + "\nPlease control the format of the selected file");
alert.setContentText(
e.getMessage() + "\nPlease control the format of the selected file");

alert.showAndWait();

} catch(UncheckedFileNotFoundException e) {
} catch (UncheckedFileNotFoundException e) {
logger.log(Level.WARNING, "FileNotFoundException: " + e.getMessage());

Alert alert = new Alert(Alert.AlertType.ERROR);
Expand All @@ -72,7 +81,10 @@ public void start(Stage stage) {
});

Scene scene = new Scene(startView, 400, 350);
scene.getStylesheets().add(STYLESHEET);
stage.setTitle("Millions");
stage.setMinWidth(900);
stage.setMinHeight(600);
stage.setScene(scene);
stage.show();
}
Expand Down
69 changes: 61 additions & 8 deletions src/main/java/millions/view/ExitView.java
Original file line number Diff line number Diff line change
@@ -1,26 +1,79 @@
package millions.view;

import java.math.BigDecimal;
import javafx.application.Platform;
import javafx.geometry.HPos;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.Separator;
import javafx.scene.layout.ColumnConstraints;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.HBox;
import javafx.scene.layout.Priority;
import javafx.scene.layout.VBox;
import millions.model.Player;

public class ExitView extends VBox {

public ExitView(Player player) {
setSpacing(12);
setSpacing(16);
setAlignment(Pos.CENTER);
setPadding(new Insets(60));

Label title = new Label("Game over");
Label weeks = new Label("Weeks traded: " + player.getTransactionArchive().countDistinctWeeks());
Label trades = new Label("Trades: " + player.getTransactionArchive().getTransactions().size());
Label netWorth = new Label("Final net worth: " + player.getNetWorth());
Label netProfit =
new Label("Total profit: " + player.getNetWorth().subtract(player.getStartingMoneh()));
Label title = new Label("GAME OVER");
title.getStyleClass().add("game-over-title");
HBox titleRow = new HBox(title);
titleRow.setAlignment(Pos.CENTER);
titleRow.setMaxWidth(Double.MAX_VALUE);

Separator sep = new Separator();
sep.setMaxWidth(320);

Label weeks = new Label(String.valueOf(player.getTransactionArchive().countDistinctWeeks()));
Label trades =
new Label(String.valueOf(player.getTransactionArchive().getTransactions().size()));
Label netWorth = new Label(ViewUtils.formatMoney(player.getNetWorth()));

BigDecimal profit = player.getNetWorth().subtract(player.getStartingMoneh());
String sign = profit.compareTo(BigDecimal.ZERO) >= 0 ? "+" : "";
Label netProfit = new Label(sign + ViewUtils.formatMoney(profit));
netProfit
.getStyleClass()
.add(profit.compareTo(BigDecimal.ZERO) >= 0 ? "status-success" : "status-error");

GridPane stats = new GridPane();
stats.setHgap(24);
stats.setVgap(12);
ColumnConstraints labelCol = new ColumnConstraints();
labelCol.setHalignment(HPos.RIGHT);
labelCol.setHgrow(Priority.NEVER);
ColumnConstraints valueCol = new ColumnConstraints();
valueCol.setHalignment(HPos.LEFT);
valueCol.setHgrow(Priority.ALWAYS);
stats.getColumnConstraints().addAll(labelCol, valueCol);

stats.addRow(0, statlabel("Weeks traded"), weeks);
stats.addRow(1, statlabel("Trades made"), trades);
stats.addRow(2, statlabel("Final net worth"), netWorth);
stats.addRow(3, statlabel("Total profit"), netProfit);

for (Label l : new Label[] {weeks, trades, netWorth, netProfit}) {
l.getStyleClass().add("stat-value");
}

Button quitButton = new Button("Quit");
quitButton.getStyleClass().add("btn-primary");
quitButton.setPrefWidth(160);
quitButton.setOnAction(event -> Platform.exit());

getChildren().addAll(title, weeks, trades, netWorth, quitButton, netProfit);
getChildren().addAll(titleRow, sep, stats, quitButton);
}

private static Label statlabel(String text) {
Label l = new Label(text);
l.getStyleClass().add("section-title");
return l;
}
}
Loading

0 comments on commit d7c9b06

Please sign in to comment.