From 9f252703717a7a2a6ef2767480ca8e4e769d21b9 Mon Sep 17 00:00:00 2001 From: dDogge <> Date: Tue, 12 Dec 2023 21:01:01 +0100 Subject: [PATCH] Sudoku board style --- app/src/main/java/gui/SudokuView.java | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/gui/SudokuView.java b/app/src/main/java/gui/SudokuView.java index 81d6bcf..7cd86eb 100644 --- a/app/src/main/java/gui/SudokuView.java +++ b/app/src/main/java/gui/SudokuView.java @@ -39,17 +39,24 @@ public class SudokuView extends JFrame { private void initializeGrid() { grid = new JTextField[9][9]; JPanel gridPanel = new JPanel(new GridLayout(9, 9)); - + for (int row = 0; row < 9; row++) { for (int col = 0; col < 9; col++) { grid[row][col] = new JTextField(2); grid[row][col].setHorizontalAlignment(JTextField.CENTER); + + // Set background color to gray for every third JTextField + if ((row / 3 + col / 3) % 2 == 1) { + grid[row][col].setBackground(Color.LIGHT_GRAY); + } + gridPanel.add(grid[row][col]); } } - + add(gridPanel, BorderLayout.CENTER); } + /** Initialize the buttons, called by the constructor */ private void initializeButtons() {