fenetre modal fermeture jeu

This commit is contained in:
martins 2022-10-24 15:28:06 +02:00
parent 6fb50882dc
commit 886b48c4c4
3 changed files with 42 additions and 1 deletions

View File

@ -12,7 +12,6 @@ public class Main {
public static void main(String[] args) {
JFrame frame = Menu.getFrame();
frame.setLocation(200, 200);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(new Dimension(1280,720));
JPanel menu=Menu.InitMenu();
Grille g = new Grille();

View File

@ -0,0 +1,36 @@
package fr.iutfbleau.projetAgile.Menu.Controller;
import java.awt.event.WindowListener;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import java.awt.event.WindowEvent;
public class ObservateurFenetre implements WindowListener{
private JFrame fenetre;
public ObservateurFenetre(JFrame fenetre0){
this.fenetre=fenetre0;
}
public void windowActivated(WindowEvent evenement){
} // premier plan
public void windowClosed(WindowEvent evenement){
} // après fermeture
public void windowClosing(WindowEvent evenement){
int confirmation = JOptionPane.showConfirmDialog(this.fenetre.getContentPane(), "Etes-vous sûr de vouloir fermer la fenetre ?", "Quitter", JOptionPane.YES_NO_OPTION);
if(confirmation == 1) return;
this.fenetre.dispose();
} // avant fermeture
public void windowDeactivated(WindowEvent evenement){
} // arrière-plan
public void windowDeiconified(WindowEvent evenement){
} // restauration
public void windowIconified(WindowEvent evenement){
} // minimisation
public void windowOpened(WindowEvent evenement){
} // après ouverture
}

View File

@ -8,6 +8,7 @@ import fr.iutfbleau.projetAgile.Menu.Controller.*;
import fr.iutfbleau.projetAgile.Puissance4.View.*;
import fr.iutfbleau.projetAgile.Puissance4.Controller.*;
import fr.iutfbleau.projetAgile.Puissance4.Model.*;
import java.awt.event.WindowListener;
public abstract class Menu{
public static String PUISSANCE_4="puissance4";
@ -159,6 +160,11 @@ public abstract class Menu{
Menu.frame.setLayout(Menu.cd);
Menu.frame.setMinimumSize(new Dimension(1280,720));
}
WindowListener[] wl=Menu.frame.getWindowListeners();
if(wl.length==0){
Menu.frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
Menu.frame.addWindowListener(new ObservateurFenetre(Menu.frame));
}
return Menu.frame;
}
}