Professional Documents
Culture Documents
Sudoko Game
Sudoko Game
*;
import java.awt.*;
import java.awt.event.*;
public SudokuGame() {
setTitle("Sudoku Game");
setSize(400, 400);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLayout(new BorderLayout());
add(sudokuPanel, BorderLayout.CENTER);
solveButton.addActionListener(new ActionListener() {
solveSudoku();
});
clearButton.addActionListener(new ActionListener() {
clearSudoku();
});
buttonPanel.add(solveButton);
buttonPanel.add(clearButton);
add(buttonPanel, BorderLayout.SOUTH);
setVisible(true);
// Read the values from the text fields and populate the board array
if (!value.isEmpty()) {
board[i][j] = Integer.parseInt(value);
if (solve(board)) {
// If a solution is found, update the text fields with the solved values
cells[i][j].setText(String.valueOf(board[i][j]));
}
} else {
if (board[row][col] == 0) {
board[row][col] = num;
if (solve(board)) {
return true;
} else {
board[row][col] = 0;
return false;
return true;
}
private boolean isValid(int[][] board, int row, int col, int num) {
return false;
return false;
return true;
cells[i][j].setText("");
new SudokuGame();