Skip to content
Snippets Groups Projects
Commit a3117d54 authored by tmp1u19's avatar tmp1u19 :octopus:
Browse files

Create the board with a GridPane, don't let stage go lower than 500x500 for...

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
parent b4cda91a
Branches
No related tags found
No related merge requests found
...@@ -2,15 +2,22 @@ import javafx.application.Application; ...@@ -2,15 +2,22 @@ import javafx.application.Application;
import javafx.geometry.Insets; import javafx.geometry.Insets;
import javafx.geometry.Pos; import javafx.geometry.Pos;
import javafx.scene.Scene; import javafx.scene.Scene;
import javafx.scene.canvas.Canvas;
import javafx.scene.canvas.GraphicsContext;
import javafx.scene.control.Button; import javafx.scene.control.Button;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.HBox; import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox; import javafx.scene.layout.VBox;
import javafx.scene.paint.Color;
import javafx.scene.shape.Rectangle;
import javafx.stage.Stage; import javafx.stage.Stage;
public class Mathdoku extends Application { 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) { public static void main(String[] args) {
launch(args); launch(args);
} }
...@@ -18,15 +25,14 @@ public class Mathdoku extends Application { ...@@ -18,15 +25,14 @@ public class Mathdoku extends Application {
@Override @Override
public void start(Stage primaryStage) { public void start(Stage primaryStage) {
VBox menu = new VBox();
menu.setPadding(new Insets(10)); 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)); topButton.setPadding(new Insets(10));
bottomButton.setPadding(new Insets(10)); topButton.setAlignment(Pos.CENTER);
bottomButton.setAlignment(Pos.CENTER);
pane.setAlignment(Pos.CENTER);
Button undo = new Button("Undo"); Button undo = new Button("Undo");
Button redo = new Button("Redo"); Button redo = new Button("Redo");
...@@ -34,21 +40,55 @@ public class Mathdoku extends Application { ...@@ -34,21 +40,55 @@ public class Mathdoku extends Application {
Button clear = new Button("Clear"); Button clear = new Button("Clear");
Button fileLoad = new Button("Load from file"); Button fileLoad = new Button("Load from file");
Button textLoad = new Button("Load from text"); 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(); draw(6);
GraphicsContext gc = c.getGraphicsContext2D();
c.setHeight(400); primaryStage.widthProperty().addListener((obs, oldVal, newVal) -> {
c.setWidth(400); //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); Scene scene = new Scene(menu);
primaryStage.setScene(scene); primaryStage.setScene(scene);
primaryStage.setMinWidth(500);
primaryStage.setMinHeight(500);
primaryStage.show(); 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);
}
}
}
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment