From c23cf8c6550994e84d60e875caaa269a3a2d35b2 Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 24 May 2022 22:57:12 +0200 Subject: [PATCH] save ok! --- ActionListener.java | 4 ---- Banniere.java | 2 +- FrameJeu.java | 2 +- Save.txt | 2 ++ SaveAndCloseListener.java | 40 +++++++++++++++++++++++++++++++++++++++ SaveListener.java | 17 +++++++++++++++++ 6 files changed, 61 insertions(+), 6 deletions(-) delete mode 100644 ActionListener.java create mode 100644 Save.txt create mode 100644 SaveAndCloseListener.java create mode 100644 SaveListener.java diff --git a/ActionListener.java b/ActionListener.java deleted file mode 100644 index a3d1061..0000000 --- a/ActionListener.java +++ /dev/null @@ -1,4 +0,0 @@ - -public interface ActionListener { - -} diff --git a/Banniere.java b/Banniere.java index b7f608d..623e2db 100644 --- a/Banniere.java +++ b/Banniere.java @@ -18,7 +18,7 @@ public class Banniere extends JPanel { // Bouton pour 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); } diff --git a/FrameJeu.java b/FrameJeu.java index 766ad7d..27bfa98 100644 --- a/FrameJeu.java +++ b/FrameJeu.java @@ -22,7 +22,7 @@ public class FrameJeu extends JFrame{ // Récupération de la bannière Banniere banniere = grille.getBanniere(); - + this.addWindowListener(new SaveAndCloseListener(grille)); // Mise en place de la bannière miseEnPage.fill = GridBagConstraints.BOTH; diff --git a/Save.txt b/Save.txt new file mode 100644 index 0000000..c6e791a --- /dev/null +++ b/Save.txt @@ -0,0 +1,2 @@ +30x9 +100000000001000000010000000000000000000100010000110000000000010000100000000000000000000000001000000010000000001100100000011011100100100000001010000000010000000100000000000000010101100100011000100101000010001011100000000000000001000100000000001100101000100000001000110000 \ No newline at end of file diff --git a/SaveAndCloseListener.java b/SaveAndCloseListener.java new file mode 100644 index 0000000..d3694bb --- /dev/null +++ b/SaveAndCloseListener.java @@ -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) { + } + +} diff --git a/SaveListener.java b/SaveListener.java new file mode 100644 index 0000000..81bca43 --- /dev/null +++ b/SaveListener.java @@ -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(); + } +}