Dernières modifications
This commit is contained in:
@@ -11,7 +11,6 @@ import fr.monkhanny.dorfromantik.controller.TutorialController;
|
|||||||
import fr.monkhanny.dorfromantik.controller.GameModeController;
|
import fr.monkhanny.dorfromantik.controller.GameModeController;
|
||||||
import fr.monkhanny.dorfromantik.gui.GameModeSelectionPanel;
|
import fr.monkhanny.dorfromantik.gui.GameModeSelectionPanel;
|
||||||
|
|
||||||
import javax.swing.ImageIcon;
|
|
||||||
import javax.swing.JFrame;
|
import javax.swing.JFrame;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -2,6 +2,7 @@ package fr.monkhanny.dorfromantik.controller;
|
|||||||
|
|
||||||
import fr.monkhanny.dorfromantik.gui.MainMenu;
|
import fr.monkhanny.dorfromantik.gui.MainMenu;
|
||||||
import fr.monkhanny.dorfromantik.gui.ButtonPanel;
|
import fr.monkhanny.dorfromantik.gui.ButtonPanel;
|
||||||
|
import fr.monkhanny.dorfromantik.listeners.GameWindowCloseListener;
|
||||||
|
|
||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
import java.awt.event.ActionEvent;
|
import java.awt.event.ActionEvent;
|
||||||
@@ -75,6 +76,8 @@ public class MainMenuButtonController implements ActionListener {
|
|||||||
|
|
||||||
this.gameFrame = gameFrame;
|
this.gameFrame = gameFrame;
|
||||||
configureFrame(this.gameFrame);
|
configureFrame(this.gameFrame);
|
||||||
|
this.gameFrame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
|
||||||
|
this.gameFrame.addWindowListener(new GameWindowCloseListener(this.gameFrame));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -3,6 +3,7 @@ package fr.monkhanny.dorfromantik.gui;
|
|||||||
import fr.monkhanny.dorfromantik.utils.FontManager;
|
import fr.monkhanny.dorfromantik.utils.FontManager;
|
||||||
import fr.monkhanny.dorfromantik.utils.ImageLoader;
|
import fr.monkhanny.dorfromantik.utils.ImageLoader;
|
||||||
import fr.monkhanny.dorfromantik.enums.Fonts;
|
import fr.monkhanny.dorfromantik.enums.Fonts;
|
||||||
|
import fr.monkhanny.dorfromantik.listeners.GameWindowCloseListener;
|
||||||
import fr.monkhanny.dorfromantik.components.Title;
|
import fr.monkhanny.dorfromantik.components.Title;
|
||||||
import fr.monkhanny.dorfromantik.Options;
|
import fr.monkhanny.dorfromantik.Options;
|
||||||
|
|
||||||
@@ -49,7 +50,8 @@ public class MainMenu extends JFrame {
|
|||||||
|
|
||||||
// Paramétrage de la fenêtre principale
|
// Paramétrage de la fenêtre principale
|
||||||
this.setTitle("Dorfromantik - Menu Principal");
|
this.setTitle("Dorfromantik - Menu Principal");
|
||||||
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
this.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
|
||||||
|
this.addWindowListener(new GameWindowCloseListener(this));
|
||||||
super.setIconImage(ImageLoader.APPLICATION_ICON);
|
super.setIconImage(ImageLoader.APPLICATION_ICON);
|
||||||
this.setMinimumSize(Options.MINIMUM_FRAME_SIZE);
|
this.setMinimumSize(Options.MINIMUM_FRAME_SIZE);
|
||||||
this.setSize(1200, 800);
|
this.setSize(1200, 800);
|
||||||
|
@@ -0,0 +1,53 @@
|
|||||||
|
package fr.monkhanny.dorfromantik.listeners;
|
||||||
|
|
||||||
|
import javax.swing.*;
|
||||||
|
import java.awt.event.WindowAdapter;
|
||||||
|
import java.awt.event.WindowEvent;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gestionnaire pour la fermeture de la fenêtre de jeu avec confirmation.
|
||||||
|
* Ce gestionnaire affiche une boîte de dialogue de confirmation avant de quitter le jeu.
|
||||||
|
*
|
||||||
|
* @version 1.0
|
||||||
|
* @author Moncef STITI
|
||||||
|
*/
|
||||||
|
public class GameWindowCloseListener extends WindowAdapter {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fenêtre à gérer.
|
||||||
|
*/
|
||||||
|
private final JFrame frame;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructeur pour initialiser le gestionnaire avec la fenêtre cible.
|
||||||
|
*
|
||||||
|
* @param frame La fenêtre à gérer
|
||||||
|
*/
|
||||||
|
public GameWindowCloseListener(JFrame frame) {
|
||||||
|
this.frame = frame;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Méthode appelée lorsque la fenêtre est en cours de fermeture.
|
||||||
|
* Affiche une boîte de dialogue de confirmation avant de quitter le jeu.
|
||||||
|
*
|
||||||
|
* @param e l'événement de fermeture de la fenêtre.
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void windowClosing(WindowEvent e) {
|
||||||
|
Object[] options = {"Oui", "Non"}; // Options personnalisées en français
|
||||||
|
int choice = JOptionPane.showOptionDialog(
|
||||||
|
frame,
|
||||||
|
"Êtes-vous sûr de vouloir quitter le jeu ?", // Message
|
||||||
|
"Quitter le jeu", // Titre
|
||||||
|
JOptionPane.YES_NO_OPTION, // Type d'option
|
||||||
|
JOptionPane.QUESTION_MESSAGE, // Icône
|
||||||
|
null, // Icône personnalisée (null pour l'icône par défaut)
|
||||||
|
options, // Options de boutons personnalisées
|
||||||
|
options[1] // Valeur par défaut ("Non")
|
||||||
|
);
|
||||||
|
if (choice == JOptionPane.YES_OPTION) {
|
||||||
|
System.exit(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user