From 9c0bc0faa823e3f168f9e81e6d03d3c37991cb51 Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 24 May 2022 22:32:34 +0200 Subject: [PATCH] probleme avec ActionListener ????git commit -m! --- ActionListener.java | 4 ++++ Banniere.java | 23 ++++++++++++----------- Grille.java | 2 +- MenuListener.java | 2 ++ NewGameListener.java | 2 ++ SettingsListener.java | 2 ++ 6 files changed, 23 insertions(+), 12 deletions(-) create mode 100644 ActionListener.java diff --git a/ActionListener.java b/ActionListener.java new file mode 100644 index 0000000..a3d1061 --- /dev/null +++ b/ActionListener.java @@ -0,0 +1,4 @@ + +public interface ActionListener { + +} diff --git a/Banniere.java b/Banniere.java index 04425e0..b7f608d 100644 --- a/Banniere.java +++ b/Banniere.java @@ -4,38 +4,38 @@ import java.awt.*; public class Banniere extends JPanel { private FrameJeu fenetre; private FrameMenu menu; + private JButton save; // Définition du constructeur - public Banniere(int mines, FrameJeu fenetre, FrameMenu menu, Dimension grilleSize) { + public Banniere(int mines, FrameJeu fenetre, FrameMenu menu, Grille grille) { super(); this.fenetre=fenetre; this.menu=menu; - this.setSize(grilleSize.width,grilleSize.height/8); + this.setSize(grille.getWidth(),grille.getHeight()/8); // On défini un style à la bannière this.setBackground(new Color(0, 236, 96)); + this.setLayout(new BorderLayout()); // Bouton pour sauver et quitter - JButton save = new JButton("Sauver et quitter"); - //save.addActionListener(new SaveListener()); - this.add(save, BorderLayout.EAST); - System.out.println(save.getLocation()); + this.save = new JButton("Sauver et quitter"); + //save.addActionListener(new SaveListener(grille)); + this.add(this.save, BorderLayout.EAST); } // Méthode pour afficher le nombre de mines restantes public void setMinesLeft(int minesLeft) { JLabel mines = new JLabel("Mines restantes : "+Integer.toString(minesLeft)); - Dimension prefSize = new Dimension(this.getWidth()/2,this.getHeight()/5); - mines.setPreferredSize(prefSize); - this.add(mines,BorderLayout.NORTH); + this.add(mines, BorderLayout.NORTH); this.repaint(); } // Méthode pour indiquer au joueur sa Victoire public void setVictoire() { + remove(this.save); JLabel victoire = new JLabel("Victoire ! Retour au menu..."); victoire.setForeground(new Color(0, 22, 236)); victoire.setFont(new Font("Arial", Font.PLAIN, 30)); - this.add(victoire,BorderLayout.CENTER); + this.add(victoire, BorderLayout.CENTER); Timer timerMenu = new Timer(7000, new MenuListener(this.fenetre, this.menu)); timerMenu.setRepeats(false); timerMenu.start(); @@ -43,10 +43,11 @@ public class Banniere extends JPanel { // Méthode pour indiquer au joueur sa Défaite public void setDefaite() { + remove(this.save); JLabel defaite = new JLabel("Défaite ! Retour au menu..."); defaite.setForeground(new Color(0, 22, 236)); defaite.setFont(new Font("Arial", Font.PLAIN, 30)); - this.add(defaite,BorderLayout.CENTER); + this.add(defaite, BorderLayout.CENTER); Timer timerMenu = new Timer(7000, new MenuListener(this.fenetre, this.menu)); timerMenu.setRepeats(false); timerMenu.start(); diff --git a/Grille.java b/Grille.java index e15bb3d..c321455 100644 --- a/Grille.java +++ b/Grille.java @@ -33,7 +33,7 @@ public class Grille extends JPanel{ this.grilleSize = new Dimension(((screenSize.height*3/4)/lignes)*colonnes, screenSize.height*3/4 ); Dimension caseSize = new Dimension(this.grilleSize.height/lignes,this.grilleSize.height/lignes); GridLayout damier = new GridLayout(lignes,colonnes); - Banniere banniere = new Banniere(mines,this.fenetre, menu, grilleSize); + Banniere banniere = new Banniere(mines,this.fenetre, menu, this); this.banniere=banniere; this.setLayout(damier); this.setSize(grilleSize); diff --git a/MenuListener.java b/MenuListener.java index a3aaef1..b055a28 100644 --- a/MenuListener.java +++ b/MenuListener.java @@ -6,6 +6,8 @@ public class MenuListener implements ActionListener{ this.fenetre=fenetre; this.menu=menu; } + + @Override public void actionPerformed(ActionEvent event){ this.menu.setVisible(true); this.fenetre.dispose(); diff --git a/NewGameListener.java b/NewGameListener.java index ebfc47e..9c42fb1 100644 --- a/NewGameListener.java +++ b/NewGameListener.java @@ -4,6 +4,8 @@ public class NewGameListener implements ActionListener{ public NewGameListener(FrameMenu menu){ this.menu=menu; } + + @Override public void actionPerformed(ActionEvent event){ int[] settings =this.menu.getSettings(); new FrameJeu(settings[0], settings[1], settings[2], this.menu); diff --git a/SettingsListener.java b/SettingsListener.java index d47c051..88b1d88 100644 --- a/SettingsListener.java +++ b/SettingsListener.java @@ -10,6 +10,8 @@ public class SettingsListener implements ChangeListener{ this.settingToSet=settingToSet; this.menu=menu; } + + @Override public void stateChanged(ChangeEvent evenement) { JSlider slider = (JSlider) evenement.getSource(); settingValue=slider.getValue();