This commit is contained in:
Adrien DICK 2024-04-03 12:08:54 +02:00
parent 2b006f67f4
commit bbdbc5b72d
6 changed files with 31 additions and 1 deletions

Binary file not shown.

View File

@ -49,8 +49,13 @@ public class Enter extends JPanel {
});
}
public int[][] getInitialGrid() {
return initialGrid;
}
@Override
protected void paintComponent(Graphics g) {
protected void paintComponent(Graphics g) {
super.paintComponent(g);
// Dessiner les contours de la grille (en gras)

Binary file not shown.

View File

@ -24,6 +24,9 @@ public class Main {
frame.add(enterPanel, BorderLayout.CENTER);
frame.add(buttonPanel, BorderLayout.SOUTH);
// Ajout de l'écouteur d'événements au bouton "Reset"
resetButton.addActionListener(new Reset(grid, enterPanel));
frame.pack();
frame.setLocationRelativeTo(null); // Centrer la fenêtre sur l'écran
frame.setVisible(true);

BIN
Reset.class Normal file

Binary file not shown.

22
Reset.java Normal file
View File

@ -0,0 +1,22 @@
import javax.swing.*;
import java.awt.event.*;
public class Reset implements ActionListener {
private int[][] grid;
private Enter enterPanel;
public Reset(int[][] grid, Enter enterPanel) {
this.grid = grid;
this.enterPanel = enterPanel;
}
@Override
public void actionPerformed(ActionEvent e) {
// Réinitialiser la grille en copiant la grille initiale
for (int i = 0; i < grid.length; i++) {
System.arraycopy(enterPanel.getInitialGrid()[i], 0, grid[i], 0, grid[i].length);
}
// Redessiner le panneau
enterPanel.repaint();
}
}