diff --git a/Mathdoku.java b/Mathdoku.java index 5424b6a5ed7f1469d80b29e1667f828c85131716..ba74b4b41d0d18ca096472f6a819ef62eec8261c 100644 --- a/Mathdoku.java +++ b/Mathdoku.java @@ -3,20 +3,22 @@ import javafx.geometry.Insets; import javafx.geometry.Pos; import javafx.scene.Scene; import javafx.scene.control.Button; -import javafx.scene.layout.GridPane; -import javafx.scene.layout.HBox; -import javafx.scene.layout.VBox; +import javafx.scene.control.TextField; +import javafx.scene.layout.*; import javafx.scene.paint.Color; import javafx.scene.shape.Rectangle; +import javafx.scene.text.Font; import javafx.stage.Stage; +import javafx.scene.control.Label; -public class Mathdoku extends Application { - private GridPane pane = new GridPane(); +public class Main extends Application { + + private GridPane grid = new GridPane(); private VBox menu = new VBox(); private HBox topButton = new HBox(); - private Rectangle[][] rectangles; - private int RESIZE = 400; + private HBox bottomButton = new HBox(); + private int n = 2; public static void main(String[] args) { launch(args); @@ -27,68 +29,91 @@ public class Mathdoku extends Application { menu.setPadding(new Insets(10)); menu.setAlignment(Pos.TOP_CENTER); - menu.setMinSize(400, 400); topButton.setPadding(new Insets(10)); - topButton.setAlignment(Pos.CENTER); + topButton.setAlignment(Pos.CENTER_LEFT); + + bottomButton.setPadding((new Insets(10))); + bottomButton.setAlignment(Pos.CENTER); - pane.setAlignment(Pos.CENTER); + grid.setAlignment(Pos.CENTER_LEFT); Button undo = new Button("Undo"); Button redo = new Button("Redo"); Button help = new Button("Help"); Button clear = new Button("Clear"); - Button fileLoad = new Button("Load from file"); - Button textLoad = new Button("Load from text"); - - /* - 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()); - */ + Button fileLoad = new Button("File"); + Button textLoad = new Button("Text"); topButton.getChildren().addAll(undo, redo, help, clear, fileLoad, textLoad); + //bottomButton.getChildren().addAll(clear, fileLoad, textLoad); - draw(6); + draw(); primaryStage.widthProperty().addListener((obs, oldVal, newVal) -> { //menu.setPrefWidth((Double) newVal); - draw(6); + //draw(); }); primaryStage.heightProperty().addListener((obs, oldVal, newVal) -> { //menu.setPrefHeight((Double) newVal); - draw(6); + //draw(); }); - menu.getChildren().addAll(topButton, pane); + menu.getChildren().addAll(topButton, grid); + Scene scene = new Scene(menu); primaryStage.setScene(scene); - primaryStage.setMinWidth(500); - primaryStage.setMinHeight(500); + primaryStage.setMinWidth(700); + primaryStage.setMinHeight(750); primaryStage.show(); } - public void draw(int n) { - - rectangles = new Rectangle[n][n]; - + public void draw() { 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); + Cell cell = new Cell("5"); + cell.setTranslateX(j*(600/n)); + cell.setTranslateY(i*(600/n)); + grid.getChildren().add(cell); } } } + class Cell extends StackPane { + + private Label label; + private TextField text; + + public Cell(String label) { + + this.label = new Label(label); + this.text = new TextField(); + + text.setPrefWidth(10); + text.setFont(Font.font(35)); + text.setStyle("-fx-text-box-border: transparent; -fx-background-color: transparent;"); + text.setAlignment(Pos.CENTER); + + Rectangle rectangle = new Rectangle(600/n, 600/n); + rectangle.setFill(null); + rectangle.setStroke(Color.BLACK); + + setAlignment(Pos.CENTER); + setPadding(new Insets(40)); + getChildren().addAll(rectangle, this.text); + } + + public String getLabel() { + return this.label.getText(); + } + + public String getText() { + return text.getText(); + } + } + }