package sudoku; import java.awt.*; import java.awt.event.*; import java.io.*; import java.util.EventListener; import javax.swing.*; /** * The SudokuPanel class currently draws the Sudoku Board and allows for text entry. New and quit work as advertised. * * @author Kyle Wilson * @version 19 November 2006 * * code for menu bar adapted from Scribble Program example by Xiaoping Jia Copyright 2002 * */ public class SudokuPanel extends JPanel implements ActionListener { /** * Constructs a SudokuPanel object and initializes a SudokuPanelListener to act as a MouseListener * */ public SudokuPanel() { super(); sBoard = new int[9][9]; setLayout(new GridLayout(9,9)); sudokuBoard = new SudokuTextField[9][9]; Font font = new Font("Monospace", Font.BOLD, 24); //SudokuPanelListener SPListener = new SudokuPanelListener(this); for(int i=0; i 9 || testint < 1) { JOptionPane.showMessageDialog(null, "Sudoku numbers must be between 1 and 9", "Invalid Entry", JOptionPane.ERROR_MESSAGE); } else sBoard[i][j] = testint; } catch(NumberFormatException e) { sBoard[i][j] = -1; } catch(NullPointerException e) { sBoard[i][j] = -1; } } } } /** * Checks for duplicates in every row, column, and blocks. * */ private void checkDuplicate() { for(int i = 0; i < 9; i++) for(int j = 0; j < 9; j++) sudokuBoard[i][j].duplicate = false; for(int a = 0; a < 9; a++) { for(int i = 0; i < 9; i++) { for(int j = 0; j < 9; j++) { if(i != j && sBoard[a][i] == sBoard[a][j] && sBoard[a][i] != -1 && sBoard[a][j] != -1) { sudokuBoard[a][i].duplicate = true; sudokuBoard[a][j].duplicate = true; } if(i != j && sBoard[i][a] == sBoard[j][a] && sBoard[i][a] != -1 && sBoard[j][a] != -1) { sudokuBoard[i][a].duplicate = true; sudokuBoard[j][a].duplicate = true; } } } } for(int a = 0; a < 3; a++) for(int i=a*3; i