forked from menault/TD3_DEV51_Qualite_Algo
		
	Affichage du jeu du pendu
This commit is contained in:
		
										
											Binary file not shown.
										
									
								
							
										
											Binary file not shown.
										
									
								
							
										
											Binary file not shown.
										
									
								
							| @@ -3,17 +3,28 @@ package fr.iut.Projet; | |||||||
| import javax.swing.*; | import javax.swing.*; | ||||||
| import java.awt.*; | import java.awt.*; | ||||||
|  |  | ||||||
|  | /** | ||||||
|  |  * Classe Action représentant la fenêtre principale du jeu "Hanging Man". | ||||||
|  |  * Affiche un message de bienvenue. | ||||||
|  |  */ | ||||||
| public class Action { | public class Action { | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * Constructeur. Crée et affiche la fenêtre du jeu avec un message. | ||||||
|  |      */ | ||||||
|     public Action() { |     public Action() { | ||||||
|         JFrame gameFrame = new JFrame("Jeu du pendu"); |         // Création de la fenêtre du jeu | ||||||
|  |         JFrame gameFrame = new JFrame("Hanging Man"); | ||||||
|         gameFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); |         gameFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); | ||||||
|         gameFrame.setSize(1040, 1000); |         gameFrame.setSize(1040, 1000); | ||||||
|         gameFrame.setLayout(new BorderLayout()); |         gameFrame.setLayout(new BorderLayout()); | ||||||
|  |  | ||||||
|  |         // Label de bienvenue | ||||||
|         JLabel label = new JLabel("Bienvenue dans le jeu !"); |         JLabel label = new JLabel("Bienvenue dans le jeu !"); | ||||||
|         label.setFont(new Font("Arial", Font.BOLD, 28)); |         label.setFont(new Font("Arial", Font.BOLD, 28)); | ||||||
|         label.setHorizontalAlignment(SwingConstants.CENTER); |         label.setHorizontalAlignment(SwingConstants.CENTER); | ||||||
|  |  | ||||||
|  |         // Ajouter le label et afficher la fenêtre | ||||||
|         gameFrame.add(label, BorderLayout.CENTER); |         gameFrame.add(label, BorderLayout.CENTER); | ||||||
|         gameFrame.setVisible(true); |         gameFrame.setVisible(true); | ||||||
|     } |     } | ||||||
|   | |||||||
| @@ -3,33 +3,46 @@ package fr.iut.Projet; | |||||||
| import javax.swing.*; | import javax.swing.*; | ||||||
| import java.awt.*; | import java.awt.*; | ||||||
|  |  | ||||||
|  | /** | ||||||
|  |  * Classe Display représentant le menu principal du jeu "Hanging Man". | ||||||
|  |  * Elle affiche le titre et le bouton Play. | ||||||
|  |  */ | ||||||
| public class Display { | public class Display { | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * Méthode principale. Crée et affiche la fenêtre du menu principal. | ||||||
|  |      * @param args Arguments de la ligne de commande (non utilisés) | ||||||
|  |      */ | ||||||
|     public static void main(String[] args) { |     public static void main(String[] args) { | ||||||
|  |         // Création de la fenêtre principale | ||||||
|         JFrame frame = new JFrame("Hanging Man"); |         JFrame frame = new JFrame("Hanging Man"); | ||||||
|         frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); |         frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); | ||||||
|         frame.setSize(1040, 1000); |         frame.setSize(1040, 1000); | ||||||
|         frame.setLayout(new BoxLayout(frame.getContentPane(), BoxLayout.Y_AXIS)); |         frame.setLayout(new BoxLayout(frame.getContentPane(), BoxLayout.Y_AXIS)); | ||||||
|  |  | ||||||
|  |         // Titre du jeu | ||||||
|         JLabel text = new JLabel("Hanging Man"); |         JLabel text = new JLabel("Hanging Man"); | ||||||
|         text.setAlignmentX(Component.CENTER_ALIGNMENT); |         text.setAlignmentX(Component.CENTER_ALIGNMENT); | ||||||
|         text.setFont(new Font("Arial", Font.BOLD, 70)); |         text.setFont(new Font("Arial", Font.BOLD, 70)); | ||||||
|  |  | ||||||
|  |         // Bouton Play | ||||||
|         JButton play = new JButton("Play"); |         JButton play = new JButton("Play"); | ||||||
|         play.setAlignmentX(Component.CENTER_ALIGNMENT); |         play.setAlignmentX(Component.CENTER_ALIGNMENT); | ||||||
|         play.setPreferredSize(new Dimension(300, 100)); |         play.setPreferredSize(new Dimension(300, 100)); | ||||||
|         play.setMaximumSize(new Dimension(300, 150)); |         play.setMaximumSize(new Dimension(300, 150)); | ||||||
|         play.setFont(new Font("Arial", Font.PLAIN, 36)); |         play.setFont(new Font("Arial", Font.PLAIN, 36)); | ||||||
|  |  | ||||||
|         // On utilise la classe séparée pour le listener |         // Listener séparé pour gérer le clic sur Play | ||||||
|         play.addActionListener(new PlayButtonListener(frame)); |         play.addActionListener(new PlayButtonListener(frame)); | ||||||
|  |  | ||||||
|  |         // Ajouter les composants avec de l'espace | ||||||
|         frame.add(Box.createVerticalGlue()); |         frame.add(Box.createVerticalGlue()); | ||||||
|         frame.add(text); |         frame.add(text); | ||||||
|         frame.add(Box.createVerticalStrut(30)); |         frame.add(Box.createVerticalStrut(30)); | ||||||
|         frame.add(play); |         frame.add(play); | ||||||
|         frame.add(Box.createVerticalGlue()); |         frame.add(Box.createVerticalGlue()); | ||||||
|  |  | ||||||
|  |         // Affichage de la fenêtre | ||||||
|         frame.setVisible(true); |         frame.setVisible(true); | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  |  | ||||||
|   | |||||||
| @@ -4,17 +4,32 @@ import javax.swing.*; | |||||||
| import java.awt.event.ActionEvent; | import java.awt.event.ActionEvent; | ||||||
| import java.awt.event.ActionListener; | import java.awt.event.ActionListener; | ||||||
|  |  | ||||||
|  | /** | ||||||
|  |  * Classe PlayButtonListener qui gère le clic sur le bouton "Play" du menu. | ||||||
|  |  * Lorsqu'on clique sur le bouton, cette classe ouvre la fenêtre du jeu | ||||||
|  |  * et ferme la fenêtre principale. | ||||||
|  |  */ | ||||||
| public class PlayButtonListener implements ActionListener { | public class PlayButtonListener implements ActionListener { | ||||||
|  |  | ||||||
|  |     /** Référence à la fenêtre principale du menu */ | ||||||
|     private JFrame parentFrame; |     private JFrame parentFrame; | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * Constructeur de PlayButtonListener. | ||||||
|  |      * @param frame La fenêtre principale à fermer après ouverture du jeu | ||||||
|  |      */ | ||||||
|     public PlayButtonListener(JFrame frame) { |     public PlayButtonListener(JFrame frame) { | ||||||
|         this.parentFrame = frame; |         this.parentFrame = frame; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * Méthode appelée lorsque le bouton est cliqué. | ||||||
|  |      * Ouvre la fenêtre du jeu et ferme la fenêtre principale. | ||||||
|  |      * @param e L'événement déclenché par le clic | ||||||
|  |      */ | ||||||
|     @Override |     @Override | ||||||
|     public void actionPerformed(ActionEvent e) { |     public void actionPerformed(ActionEvent e) { | ||||||
|         new Action();        // ouvre la fenêtre du jeu |         new Action();        // Ouvre la fenêtre du jeu | ||||||
|         parentFrame.dispose(); |         parentFrame.dispose(); // Ferme la fenêtre principale | ||||||
|     } |     } | ||||||
| } | } | ||||||
		Reference in New Issue
	
	Block a user