diff --git a/Main.class b/Main.class new file mode 100644 index 0000000..585252d Binary files /dev/null and b/Main.class differ diff --git a/Main.java b/Main.java index 1211a49..14399b0 100644 --- a/Main.java +++ b/Main.java @@ -1,8 +1,15 @@ -import javax.swing.JFrame; -import javax.swing.SwingUtilities; +import javax.swing.*; public class Main { public static void main(String[] args) { - + int[][] grid = SudokuGenerator.generateGrid(); + + JFrame frame = new JFrame("Sudoku"); + frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + SudokuDraw sudokuDraw = new SudokuDraw(grid); + frame.add(sudokuDraw); + frame.pack(); + frame.setLocationRelativeTo(null); // Centrer la fenêtre sur l'écran + frame.setVisible(true); } } diff --git a/SudokuDraw.class b/SudokuDraw.class new file mode 100644 index 0000000..2872e91 Binary files /dev/null and b/SudokuDraw.class differ diff --git a/SudokuDraw.java b/SudokuDraw.java new file mode 100644 index 0000000..8e391af --- /dev/null +++ b/SudokuDraw.java @@ -0,0 +1,43 @@ +import javax.swing.*; +import java.awt.*; + +public class SudokuDraw extends JPanel { + private static final int GRID_SIZE = 3; + private static final int REGION_SIZE = 3; + private static final int CELL_SIZE = 50; + + private int[][] grid; + + public SudokuDraw(int[][] grid) { + this.grid = grid; + setPreferredSize(new Dimension(GRID_SIZE * REGION_SIZE * CELL_SIZE, GRID_SIZE * REGION_SIZE * CELL_SIZE)); + } + + @Override + protected void paintComponent(Graphics g) { + super.paintComponent(g); + + // Dessiner des lignes plus épaisses pour la grille 3x3 + g.setColor(Color.BLACK); + for (int i = 0; i <= GRID_SIZE * REGION_SIZE; i++) { + if (i % REGION_SIZE == 0) { + g.fillRect(0, i * CELL_SIZE - 2, GRID_SIZE * REGION_SIZE * CELL_SIZE, 4); + g.fillRect(i * CELL_SIZE - 2, 0, 4, GRID_SIZE * REGION_SIZE * CELL_SIZE); + } else { + g.fillRect(0, i * CELL_SIZE - 1, GRID_SIZE * REGION_SIZE * CELL_SIZE, 2); + g.fillRect(i * CELL_SIZE - 1, 0, 2, GRID_SIZE * REGION_SIZE * CELL_SIZE); + } + } + + // Dessiner les valeurs de la grille + g.setColor(Color.BLACK); + for (int i = 0; i < grid.length; i++) { + for (int j = 0; j < grid[i].length; j++) { + int value = grid[i][j]; + if (value != 0) { + g.drawString(String.valueOf(value), j * CELL_SIZE + CELL_SIZE / 2, i * CELL_SIZE + CELL_SIZE / 2); + } + } + } + } +} diff --git a/SudokuGenerator.class b/SudokuGenerator.class new file mode 100644 index 0000000..2331083 Binary files /dev/null and b/SudokuGenerator.class differ diff --git a/SudokuGenerator.java b/SudokuGenerator.java index 77f4740..de7719d 100644 --- a/SudokuGenerator.java +++ b/SudokuGenerator.java @@ -1,3 +1,17 @@ public class SudokuGenerator { - -} \ No newline at end of file + public static int[][] generateGrid() { + int[][] grid = { + {0, 0, 0, 9, 0, 5, 0, 0, 4}, + {5, 0, 3, 0, 0, 4, 0, 8, 7}, + {0, 0, 0, 7, 0, 0, 6, 0, 3}, + {9, 0, 0, 0, 3, 4, 0, 8, 0}, + {0, 4, 0, 0, 1, 0, 0, 7, 0}, + {0, 2, 0, 5, 7, 0, 0, 0, 6}, + {4, 0, 9, 0, 0, 2, 0, 0, 0}, + {6, 0, 7, 9, 0, 3, 0, 2, 1}, + {2, 0, 0, 6, 5, 0, 0, 0, 0} + }; + + return grid; + } +} diff --git a/SudokuPanel.class b/SudokuPanel.class new file mode 100644 index 0000000..4d692d7 Binary files /dev/null and b/SudokuPanel.class differ