SAE21_2023/SudokuDraw.java
2024-04-03 11:29:06 +02:00

32 lines
954 B
Java

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 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);
}
}
}
}
}