From a3117d548f58a32622b0dfba804c6f2cbe1414f0 Mon Sep 17 00:00:00 2001
From: Theodora-Mara Pislar <tmp1u19@soton.ac.uk>
Date: Wed, 26 Feb 2020 20:34:24 +0000
Subject: [PATCH] Create the board with a GridPane, don't let stage go lower
 than 500x500 for the game to be actually played; need to work on the resizing

---
 Mathdoku.java | 72 +++++++++++++++++++++++++++++++++++++++------------
 1 file changed, 56 insertions(+), 16 deletions(-)

diff --git a/Mathdoku.java b/Mathdoku.java
index 430ddd5..5424b6a 100644
--- a/Mathdoku.java
+++ b/Mathdoku.java
@@ -2,15 +2,22 @@ import javafx.application.Application;
 import javafx.geometry.Insets;
 import javafx.geometry.Pos;
 import javafx.scene.Scene;
-import javafx.scene.canvas.Canvas;
-import javafx.scene.canvas.GraphicsContext;
 import javafx.scene.control.Button;
+import javafx.scene.layout.GridPane;
 import javafx.scene.layout.HBox;
 import javafx.scene.layout.VBox;
+import javafx.scene.paint.Color;
+import javafx.scene.shape.Rectangle;
 import javafx.stage.Stage;
 
 public class Mathdoku extends Application {
 
+    private GridPane pane = new GridPane();
+    private VBox menu = new VBox();
+    private HBox topButton = new HBox();
+    private Rectangle[][] rectangles;
+    private int RESIZE = 400;
+
     public static void main(String[] args) {
         launch(args);
     }
@@ -18,15 +25,14 @@ public class Mathdoku extends Application {
     @Override
     public void start(Stage primaryStage) {
 
-        VBox menu = new VBox();
         menu.setPadding(new Insets(10));
-        menu.setAlignment(Pos.CENTER);
+        menu.setAlignment(Pos.TOP_CENTER);
+        menu.setMinSize(400, 400);
 
-        HBox topButton = new HBox();
-        HBox bottomButton = new HBox();
         topButton.setPadding(new Insets(10));
-        bottomButton.setPadding(new Insets(10));
-        bottomButton.setAlignment(Pos.CENTER);
+        topButton.setAlignment(Pos.CENTER);
+
+        pane.setAlignment(Pos.CENTER);
 
         Button undo = new Button("Undo");
         Button redo = new Button("Redo");
@@ -34,21 +40,55 @@ public class Mathdoku extends Application {
         Button clear = new Button("Clear");
         Button fileLoad = new Button("Load from file");
         Button textLoad = new Button("Load from text");
-        Button submit = new Button("Submit");
 
-        topButton.getChildren().addAll(undo, redo, help);
-        bottomButton.getChildren().addAll(clear, fileLoad, textLoad, submit);
+        /*
+        undo.prefWidthProperty().bind(menu.widthProperty());
+        redo.prefWidthProperty().bind(menu.widthProperty());
+        help.prefWidthProperty().bind(menu.widthProperty());
+        clear.prefWidthProperty().bind(menu.widthProperty());
+        fileLoad.prefWidthProperty().bind(menu.widthProperty());
+        textLoad.prefWidthProperty().bind(menu.widthProperty());
+        */
+
+        topButton.getChildren().addAll(undo, redo, help, clear, fileLoad, textLoad);
 
-        Canvas c = new Canvas();
-        GraphicsContext gc = c.getGraphicsContext2D();
+        draw(6);
 
-        c.setHeight(400);
-        c.setWidth(400);
+        primaryStage.widthProperty().addListener((obs, oldVal, newVal) -> {
+            //menu.setPrefWidth((Double) newVal);
+            draw(6);
+        });
 
-        menu.getChildren().addAll(topButton, c, bottomButton);
+        primaryStage.heightProperty().addListener((obs, oldVal, newVal) -> {
+            //menu.setPrefHeight((Double) newVal);
+            draw(6);
+        });
+
+        menu.getChildren().addAll(topButton, pane);
 
         Scene scene = new Scene(menu);
         primaryStage.setScene(scene);
+
+        primaryStage.setMinWidth(500);
+        primaryStage.setMinHeight(500);
+
         primaryStage.show();
     }
+
+    public void draw(int n) {
+
+        rectangles = new Rectangle[n][n];
+
+        for(int i = 0; i < n; i ++) {
+            for(int j = 0; j < n; j ++) {
+                Rectangle rectangle = new Rectangle(RESIZE/n, RESIZE/n, Color.WHITE);
+                rectangle.setStroke(Color.BLACK);
+                rectangles[i][j] = rectangle;
+                pane.setRowIndex(rectangle, i);
+                pane.setColumnIndex(rectangle, j);
+                pane.getChildren().add(rectangle);
+            }
+        }
+    }
+
 }
-- 
GitLab