This commit is contained in:
Adrien DICK 2024-04-03 11:51:47 +02:00
parent 3f73c761a6
commit 8bee2d784a
6 changed files with 58 additions and 13 deletions

Binary file not shown.

View File

@ -50,9 +50,24 @@ public class Enter extends JPanel {
} }
@Override @Override
protected void paintComponent(Graphics g) { protected void paintComponent(Graphics g) {
super.paintComponent(g); super.paintComponent(g);
// Dessiner les contours de la grille (en gras)
Graphics2D g2d = (Graphics2D) g;
Stroke oldStroke = g2d.getStroke(); // Sauvegarder le style de ligne précédent
g2d.setStroke(new BasicStroke(4)); // Épaisseur de ligne de 4 pixels
for (int i = 0; i <= GRID_SIZE * REGION_SIZE; i++) {
if (i % REGION_SIZE == 0) {
g2d.drawLine(0, i * CELL_SIZE, GRID_SIZE * REGION_SIZE * CELL_SIZE, i * CELL_SIZE);
g2d.drawLine(i * CELL_SIZE, 0, i * CELL_SIZE, GRID_SIZE * REGION_SIZE * CELL_SIZE);
}
}
// Rétablir le style de ligne précédent
g2d.setStroke(oldStroke);
// Dessiner les cases de la grille // Dessiner les cases de la grille
for (int i = 0; i < GRID_SIZE * REGION_SIZE; i++) { for (int i = 0; i < GRID_SIZE * REGION_SIZE; i++) {
for (int j = 0; j < GRID_SIZE * REGION_SIZE; j++) { for (int j = 0; j < GRID_SIZE * REGION_SIZE; j++) {
@ -64,5 +79,7 @@ public class Enter extends JPanel {
} }
} }
} }
} }
} }

Binary file not shown.

View File

@ -1,4 +1,6 @@
import javax.swing.*; import javax.swing.*;
import java.awt.BorderLayout;
public class Main { public class Main {
public static void main(String[] args) { public static void main(String[] args) {
@ -10,7 +12,18 @@ public class Main {
JFrame frame = new JFrame("Sudoku"); JFrame frame = new JFrame("Sudoku");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Enter enterPanel = new Enter(grid); // Utilisation de la classe Enter pour permettre la saisie des valeurs Enter enterPanel = new Enter(grid); // Utilisation de la classe Enter pour permettre la saisie des valeurs
frame.add(enterPanel);
// Ajout de deux boutons
JButton solveButton = new JButton("Solve");
JButton resetButton = new JButton("Reset");
JPanel buttonPanel = new JPanel();
buttonPanel.add(solveButton);
buttonPanel.add(resetButton);
// Ajout des composants au frame
frame.add(enterPanel, BorderLayout.CENTER);
frame.add(buttonPanel, BorderLayout.SOUTH);
frame.pack(); frame.pack();
frame.setLocationRelativeTo(null); // Centrer la fenêtre sur l'écran frame.setLocationRelativeTo(null); // Centrer la fenêtre sur l'écran
frame.setVisible(true); frame.setVisible(true);

Binary file not shown.

View File

@ -17,6 +17,21 @@ public class SudokuDraw extends JPanel {
protected void paintComponent(Graphics g) { protected void paintComponent(Graphics g) {
super.paintComponent(g); super.paintComponent(g);
Graphics2D g2d = (Graphics2D) g;
// Définir l'épaisseur de la ligne
g2d.setStroke(new BasicStroke(20)); // Épaisseur de ligne de 4 pixels
// Dessiner les lignes de la grille (en gras pour les contours)
for (int i = 0; i <= GRID_SIZE * REGION_SIZE; i++) {
if (i % REGION_SIZE == 0) {
g2d.drawRect(0, i * CELL_SIZE - 2, GRID_SIZE * REGION_SIZE * CELL_SIZE, 4);
g2d.drawRect(i * CELL_SIZE - 2, 0, 4, GRID_SIZE * REGION_SIZE * CELL_SIZE);
} else {
g2d.drawRect(0, i * CELL_SIZE - 1, GRID_SIZE * REGION_SIZE * CELL_SIZE, 2);
g2d.drawRect(i * CELL_SIZE - 1, 0, 2, GRID_SIZE * REGION_SIZE * CELL_SIZE);
}
}
// Dessiner les valeurs de la grille // Dessiner les valeurs de la grille
g.setColor(Color.BLACK); g.setColor(Color.BLACK);
for (int i = 0; i < grid.length; i++) { for (int i = 0; i < grid.length; i++) {