import java.util.Scanner; import java.awt.*; import javax.swing.*; class SudokuDisplay extends javax.swing.JFrame { private JTextArea[][] cells = new JTextArea[Sudoku.SIZE][Sudoku.SIZE]; public SudokuDisplay() { this.setTitle("SudoKu"); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); this.setLayout(new GridLayout(Sudoku.SIZE, Sudoku.SIZE)); for(int i = 0; i < Sudoku.SIZE; i++) { for (int j=0; j < Sudoku.SIZE; j++) { cells[i][j] = new JTextArea(); cells[i][j].setFont(new Font("Arial", Font.BOLD, 16)); cells[i][j].setBorder(BorderFactory.createLineBorder(Color.BLUE, 1)); if ((i/3 + j/3) %2 == 0) cells[i][j].setBackground(Color.WHITE); else cells[i][j].setBackground(Color.YELLOW); cells[i][j].setColumns(1); this.getContentPane().add(cells[i][j]); } } this.setSize(400, 400); this.setVisible(true); } public void setValue(int i, int j, String s) { String t = ""; int k; cells[i][j].setForeground(Color.DARK_GRAY); if (s.length() == 1) cells[i][j].setFont(new Font("Arial", Font.BOLD, 16)); else cells[i][j].setFont(new Font("Arial", Font.PLAIN, 10)); k = 0; while (k < s.length()-3) { t = t + s.substring(k, k+3) + "\n"; k = k+3; } t = t + s.substring(k); cells[i][j].setText(t); } public String getValue(int i, int j) { System.out.println("(" + i + "," + j + ")=" + cells[i][j].getText()); return cells[i][j].getText(); } } class SudokuCell { private boolean[] contents = new boolean[Sudoku.SIZE]; // Constructor to ensure that only the valid value is filled in. SudokuCell(int value) { int i; if ((value < 1) || (value > Sudoku.SIZE)) { for (i=0; i 0) && (value <= Sudoku.SIZE)) { b = contents[value -1]; contents[value-1] = false; } return b; } // test to check if the cell is frozen boolean isFrozen() { boolean frozen = false; int i; for (i=0; i= SIZE) || (j < 0) || (j > SIZE)) return; if ((val.length() == 0) || (val.length() > 1)) { board[i][j] = new SudokuCell(); return; } if ((val.charAt(0) < '0') || (val.charAt(0) > ('0' + Sudoku.SIZE))) { board[i][j] = new SudokuCell(); return; } board[i][j] = new SudokuCell(val.charAt(0) - '0'); } boolean doRow(int i) { int j, t; boolean change = false; if ((i < 0) || (i >= SIZE)) return change; for (j=0; j= SIZE)) return change; for (j=0; j=BLKSIZE) || (yblk<0) || (yblk>=BLKSIZE)) return change; for (i=0; i