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

Delete Mathdoku.java

parent 8443e4d9
No related branches found
No related tags found
No related merge requests found
import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Button;
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 grid = new GridPane();
private VBox menu = new VBox();
private HBox topButton = new HBox();
private HBox bottomButton = new HBox();
private int n = 4;
private Cell[][] cells;
private int[][] values;
public static void main(String[] args) {
launch(args);
}
@Override
public void start(Stage primaryStage) {
menu.setPadding(new Insets(10));
menu.setAlignment(Pos.TOP_CENTER);
topButton.setPadding(new Insets(10));
topButton.setAlignment(Pos.CENTER_LEFT);
bottomButton.setPadding((new Insets(10)));
bottomButton.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("File");
Button textLoad = new Button("Text");
topButton.getChildren().addAll(undo, redo, help, clear, fileLoad, textLoad);
//bottomButton.getChildren().addAll(clear, fileLoad, textLoad);
draw();
retainValues();
primaryStage.widthProperty().addListener((obs, oldVal, newVal) -> {
//menu.setPrefWidth((Double) newVal);
draw();
drawInput();
});
primaryStage.heightProperty().addListener((obs, oldVal, newVal) -> {
//menu.setPrefHeight((Double) newVal);
draw();
drawInput();
});
menu.getChildren().addAll(topButton, grid);
Scene scene = new Scene(menu);
primaryStage.setScene(scene);
primaryStage.setMinWidth(700);
primaryStage.setMinHeight(750);
primaryStage.show();
}
public void draw() {
cells = new Cell[n][n];
for(int i = 0; i < n; i ++) {
for(int j = 0; j < n; j ++) {
Cell cell = new Cell("");
cell.setTranslateX(j*(600/n));
cell.setTranslateY(i*(600/n));
cells[i][j] = cell;
grid.getChildren().add(cell);
}
}
}
public void drawInput() {
for(int i = 0; i < n; i ++) {
for(int j = 0; j < n; j ++) {
if(values[i][j] != 0) {
cells[i][j].setText(String.valueOf(values[i][j]));
}
}
}
}
public void retainValues() {
values = new int[n][n];
for(int i = 0; i < n; i ++) {
for(int j = 0; j < n; j ++) {
int finalI = i;
int finalJ = j;
cells[i][j].getText().setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent actionEvent) {
values[finalI][finalJ] = Integer.parseInt(cells[finalI][finalJ].getText().getText());
}
});
}
}
}
class Cell extends StackPane {
private Label label;
private TextField text;
public Cell(String label) {
this.label = new Label(label);
this.text = new TextField();
this.label.setFont(Font.font(20));
//this.label.setAlignment(Pos.TOP_LEFT);
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);
setPadding(new Insets(40));
getChildren().addAll(rectangle, this.text, this.label);
}
public String getLabel() {
return this.label.getText();
}
public TextField getText() {
return this.text;
}
public void setText(String text) {
this.text.setText(text);
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment