This commit is contained in:
Haïssous Kayyissa 2022-05-24 22:57:12 +02:00
parent 9c0bc0faa8
commit c23cf8c655
6 changed files with 61 additions and 6 deletions

View File

@ -1,4 +0,0 @@
public interface ActionListener {
}

View File

@ -18,7 +18,7 @@ public class Banniere extends JPanel {
// Bouton pour sauver et quitter // Bouton pour sauver et quitter
this.save = new JButton("Sauver et quitter"); this.save = new JButton("Sauver et quitter");
//save.addActionListener(new SaveListener(grille)); save.addActionListener(new SaveListener(grille, fenetre));
this.add(this.save, BorderLayout.EAST); this.add(this.save, BorderLayout.EAST);
} }

View File

@ -22,7 +22,7 @@ public class FrameJeu extends JFrame{
// Récupération de la bannière // Récupération de la bannière
Banniere banniere = grille.getBanniere(); Banniere banniere = grille.getBanniere();
this.addWindowListener(new SaveAndCloseListener(grille));
// Mise en place de la bannière // Mise en place de la bannière
miseEnPage.fill = GridBagConstraints.BOTH; miseEnPage.fill = GridBagConstraints.BOTH;

2
Save.txt Normal file
View File

@ -0,0 +1,2 @@
30x9
100000000001000000010000000000000000000100010000110000000000010000100000000000000000000000001000000010000000001100100000011011100100100000001010000000010000000100000000000000010101100100011000100101000010001011100000000000000001000100000000001100101000100000001000110000

40
SaveAndCloseListener.java Normal file
View File

@ -0,0 +1,40 @@
import java.awt.event.*;
public class SaveAndCloseListener implements WindowListener{
private Grille grille;
public SaveAndCloseListener(Grille grille){
this.grille=grille;
}
@Override
public void windowOpened(WindowEvent e) {
}
@Override
public void windowClosing(WindowEvent e) {
SaveManager saveManager = new SaveManager();
saveManager.save(this.grille, "Save.txt");
SaveManager.SaveData donnees = saveManager.load("Save.txt");
}
@Override
public void windowClosed(WindowEvent e) {
}
@Override
public void windowIconified(WindowEvent e) {
}
@Override
public void windowDeiconified(WindowEvent e) {
}
@Override
public void windowActivated(WindowEvent e) {
}
@Override
public void windowDeactivated(WindowEvent e) {
}
}

17
SaveListener.java Normal file
View File

@ -0,0 +1,17 @@
import java.awt.event.*;
public class SaveListener implements ActionListener {
private Grille grille;
private FrameJeu fenetre;
public SaveListener(Grille grille, FrameJeu fenetre){
this.grille=grille;
this.fenetre=fenetre;
}
@Override
public void actionPerformed(ActionEvent event){
SaveManager saveManager = new SaveManager();
saveManager.save(this.grille, "Save.txt");
SaveManager.SaveData donnees = saveManager.load("Save.txt");
this.fenetre.dispose();
}
}