30 lines
1.4 KiB
Java
30 lines
1.4 KiB
Java
|
import java.awt.*;
|
||
|
|
||
|
public class GrillePainter {
|
||
|
public static void dessinerGrille(Graphics g, SaisieGrille panel) {
|
||
|
Graphics2D g2d = (Graphics2D) g;
|
||
|
Stroke ancienStroke = g2d.getStroke();
|
||
|
g2d.setStroke(new BasicStroke(4));
|
||
|
|
||
|
for (int i = 0; i <= panel.getTailleGrille() * panel.getTailleRegion(); i++) {
|
||
|
if (i % panel.getTailleRegion() == 0) {
|
||
|
g2d.drawLine(0, i * panel.getTailleCellule(), panel.getTailleGrille() * panel.getTailleRegion() * panel.getTailleCellule(), i * panel.getTailleCellule());
|
||
|
g2d.drawLine(i * panel.getTailleCellule(), 0, i * panel.getTailleCellule(), panel.getTailleGrille() * panel.getTailleRegion() * panel.getTailleCellule());
|
||
|
}
|
||
|
}
|
||
|
|
||
|
g2d.setStroke(ancienStroke);
|
||
|
|
||
|
for (int i = 0; i < panel.getTailleGrille() * panel.getTailleRegion(); i++) {
|
||
|
for (int j = 0; j < panel.getTailleGrille() * panel.getTailleRegion(); j++) {
|
||
|
g.setColor(Color.BLACK);
|
||
|
g.drawRect(j * panel.getTailleCellule(), i * panel.getTailleCellule(), panel.getTailleCellule(), panel.getTailleCellule());
|
||
|
int valeur = panel.getGrille()[i][j];
|
||
|
if (valeur != 0) {
|
||
|
g.drawString(String.valueOf(valeur), j * panel.getTailleCellule() + panel.getTailleCellule() / 2, i * panel.getTailleCellule() + panel.getTailleCellule() / 2);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|