From 4ef9760f539337ff43ca7e4d3efd72dbc7674b10 Mon Sep 17 00:00:00 2001 From: tmp1u19 <tmp1u19@soton.ac.uk> Date: Thu, 12 Mar 2020 17:08:51 +0000 Subject: [PATCH] Cell class which defines a cell in the grid of the game. --- Cell.java | 63 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 Cell.java diff --git a/Cell.java b/Cell.java new file mode 100644 index 0000000..0757b12 --- /dev/null +++ b/Cell.java @@ -0,0 +1,63 @@ +import javafx.geometry.Pos; +import javafx.scene.control.TextField; +import javafx.scene.layout.*; +import javafx.scene.control.Label; +import javafx.scene.text.Font; + +public class Cell extends Pane { + + private Label label = new Label(); + private TextField input; + private int i; + private int j; + + public Cell(int n, int i, int j) { + + this.i = i; + this.j = j; + + input = new TextField(); + setPrefSize(400/n, 400/n); + + setStyle("- fx-background-color: transparent;"); + + input.setStyle("-fx-text-box-border: transparent; -fx-background-color: transparent;"); + input.setAlignment(Pos.CENTER); + input.setFont(Font.font(35)); + input.setPrefWidth(400/n); + input.setPrefHeight(400/n); + + getChildren().add(input); + } + + public void setLabel(String label) { + + this.label.setText(label); + this.label.setAlignment(Pos.TOP_LEFT); + getChildren().add(this.label); + } + + public String getLabel() { + return label.getText(); + } + + public TextField getTextField() { + return input; + } + + public boolean isNumeric(String text) { + try { + Integer.parseInt(text); + return true; + } catch(Exception e) { + return false; + } + } + public int getRow() { + return i; + } + + public int getColumn() { + return j; + } +} -- GitLab