Auto
This commit is contained in:
parent
bf2efc08c8
commit
38b8e6d31c
BIN
Main.class
Normal file
BIN
Main.class
Normal file
Binary file not shown.
13
Main.java
13
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);
|
||||
}
|
||||
}
|
||||
|
BIN
SudokuDraw.class
Normal file
BIN
SudokuDraw.class
Normal file
Binary file not shown.
43
SudokuDraw.java
Normal file
43
SudokuDraw.java
Normal file
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
BIN
SudokuGenerator.class
Normal file
BIN
SudokuGenerator.class
Normal file
Binary file not shown.
@ -1,3 +1,17 @@
|
||||
public class SudokuGenerator {
|
||||
|
||||
}
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
BIN
SudokuPanel.class
Normal file
BIN
SudokuPanel.class
Normal file
Binary file not shown.
Loading…
Reference in New Issue
Block a user