This commit is contained in:
Adrian POURCHOT 2024-09-18 17:24:33 +02:00
parent 4d7c490f87
commit ee94179c71
7 changed files with 42 additions and 35 deletions

View File

@ -4,7 +4,7 @@ import java.awt.event.*;
import java.lang.*;
public class Boutons extends JPanel implements WindowListener{
public class Boutons extends JPanel{
public Boutons() {
super();
@ -72,32 +72,4 @@ public class Boutons extends JPanel implements WindowListener{
this.add(five, gbc);
}
public void windowDeactivated(WindowEvent evenement){
}
public void windowActivated(WindowEvent evenement){
}
public void windowClosed(WindowEvent evenement){
}
public void windowClosing(WindowEvent evenement){
JOptionPane exit = new JOptionPane();
int rep = exit.showConfirmDialog(this, "Etes vous certain de vouloir quitter?", "Quitter", JOptionPane.YES_NO_OPTION);
if (rep == JOptionPane.YES_OPTION){
Main.fenetre.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
} else if (rep == JOptionPane.NO_OPTION){
Main.fenetre.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
}
}
public void windowDeiconified(WindowEvent evenement){
}
public void windowIconified(WindowEvent evenement){
}
public void windowOpened(WindowEvent evenement){
}
}

Binary file not shown.

Binary file not shown.

View File

@ -0,0 +1,40 @@
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.util.*;
import java.io.*;
public class Fenetre extends JFrame{
public Fenetre(){
Boutons pan = new Boutons();
this.setSize(450, 450);
this.setLocation(500, 500);
this.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
this.setContentPane(pan);
addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
if(fermerFenetre()==true){
dispose();
System.exit(0);
}
return;
}
});
}
private boolean fermerFenetre() {
JOptionPane option = new JOptionPane("Voulez-vous vraiment quitter ce programme ?", JOptionPane.QUESTION_MESSAGE, JOptionPane.YES_NO_OPTION);
JDialog confirmation = option.createDialog(this, "Confirmation de fermeture");
confirmation.setSize(400, 120);
confirmation.setVisible(true);
int result = (int) option.getValue();
confirmation.dispose();
return result == JOptionPane.YES_OPTION;
}
}

View File

@ -6,15 +6,10 @@ import java.lang.*;
public class Main{
static JFrame fenetre = new JFrame();
static Fenetre fenetre = new Fenetre();
public static void main(String[] args) {
Boutons pan = new Boutons();
fenetre.setSize(500, 500);
fenetre.setLocation(250, 250);
fenetre.addWindowListener(pan);
fenetre.add(pan);
fenetre.setVisible(true);
}
}