diff --git a/pom.xml b/pom.xml
index df69562..2d6f2b7 100644
--- a/pom.xml
+++ b/pom.xml
@@ -13,5 +13,13 @@
8
UTF-8
+
+
+ org.junit.jupiter
+ junit-jupiter-api
+ 5.9.1
+ test
+
+
\ No newline at end of file
diff --git a/src/test/java/MainTest.java b/src/test/java/MainTest.java
new file mode 100644
index 0000000..ca38d57
--- /dev/null
+++ b/src/test/java/MainTest.java
@@ -0,0 +1,48 @@
+import org.junit.Test;
+
+import javax.swing.*;
+
+import static org.junit.jupiter.api.Assertions.*;
+
+class MainTest extends Main {
+
+ @org.junit.jupiter.api.Test
+ void testField() {
+
+ JPanel setupGameField = setupGameField(360);
+
+ JLabel[][] labelField = getLabelField();
+
+ for (int i = 0; i < 9; i++) {
+ for (int j = 0; j < 9; j++) {
+ labelField[i][j].setText(String.valueOf(j));
+ }
+ }
+
+ boolean a = true;
+
+ for (int i = 0; i < 9; i++) {
+ for (int j = 0; j < 9; j++) {
+ String s = labelField[i][j].getText();
+ try {
+ Integer integer = Integer.valueOf(s);
+ if (j != integer) {
+ a = false;
+ }
+ } catch (NumberFormatException e) {
+ assertTrue(false);
+ }
+ }
+ }
+
+ assertTrue(a);
+
+
+
+ }
+
+ @org.junit.jupiter.api.Test
+ void testBla() {
+ assertTrue(true);
+ }
+}
\ No newline at end of file
diff --git a/sudokuExample/src/Main.java b/sudokuExample/src/Main.java
index 7efb163..e02ffa2 100644
--- a/sudokuExample/src/Main.java
+++ b/sudokuExample/src/Main.java
@@ -6,8 +6,18 @@ import java.awt.event.ActionListener;
public class Main {
- public static void main(String[] args) {
+ private static JPanel[][] gameField;
+ private static JLabel[][] labelField;
+
+ public static JPanel[][] getGameField() {
+ return gameField;
+ }
+ public static JLabel[][] getLabelField() {
+ return labelField;
+ }
+
+ public static void main(String[] args) {
java.awt.EventQueue.invokeLater(new Runnable() {
@Override
@@ -25,6 +35,10 @@ public class Main {
rootPanel.setBackground(Color.LIGHT_GRAY);
rootPanel.setLayout(null);
+ JPanel gamePanel = setupGameField(360);
+ gamePanel.setBounds(70, 50, 360, 360);
+ rootPanel.add(gamePanel);
+
main.setContentPane(rootPanel);
JButton back = new JButton();
@@ -38,9 +52,57 @@ public class Main {
newButton.setBounds(395, 5, 100, 25);
newButton.setText("New");
rootPanel.add(newButton);
+
}
});
}
+
+ protected static JPanel setupGameField(int widthHeight) {
+
+ int nrOfFields = 9;
+ int border = 1;
+ int size = widthHeight/nrOfFields - (nrOfFields*border)/nrOfFields;
+
+ JPanel fieldRoot = new JPanel();
+ fieldRoot.setVisible(true);
+ fieldRoot.setLayout(null);
+
+ gameField = new JPanel[nrOfFields][];
+ labelField = new JLabel[nrOfFields][];
+
+ int gapi = 0, gapj = 0;
+
+ for (int i = 0; i < nrOfFields; i++) {
+
+ gameField[i] = new JPanel[nrOfFields];
+ labelField[i] = new JLabel[nrOfFields];
+
+ for (int j = 0; j < nrOfFields; j++) {
+
+ gameField[i][j] = new JPanel();
+ gameField[i][j].setBounds(
+ j * size + border*(j+1),
+ i * size + border*(i+1),
+ size, size);
+ gameField[i][j].setBackground(Color.BLUE);
+ gameField[i][j].setVisible(true);
+ fieldRoot.add(gameField[i][j]);
+
+ labelField[i][j] = new JLabel("", SwingConstants.CENTER);
+ labelField[i][j].setBackground(Color.GREEN);
+ labelField[i][j].setForeground(Color.MAGENTA);
+ labelField[i][j].setFont(new Font("Times new Roman", Font.BOLD, 25));
+
+ labelField[i][j].setBackground(Color.CYAN);
+ labelField[i][j].setText("0");
+
+ gameField[i][j].add(labelField[i][j]);
+
+ }
+ }
+
+ return fieldRoot;
+ }
}
// JFrame jFrame = new JFrame();