forked from menault/TD3_DEV51_Qualite_Algo
Compare commits
4 Commits
6a8bc81e01
...
1037a9ff92
| Author | SHA1 | Date | |
|---|---|---|---|
| 1037a9ff92 | |||
| 0d074ad1b6 | |||
| 3ab03c6b3e | |||
| 3bc6530305 |
31
src/fr/iut/Projet/Action.java
Normal file
31
src/fr/iut/Projet/Action.java
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
package fr.iut.Projet;
|
||||||
|
|
||||||
|
import javax.swing.*;
|
||||||
|
import java.awt.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Classe Action représentant la fenêtre principale du jeu "Hanging Man".
|
||||||
|
* Affiche un message de bienvenue.
|
||||||
|
*/
|
||||||
|
public class Action {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructeur. Crée et affiche la fenêtre du jeu avec un message.
|
||||||
|
*/
|
||||||
|
public Action() {
|
||||||
|
// Création de la fenêtre du jeu
|
||||||
|
JFrame gameFrame = new JFrame("Hanging Man");
|
||||||
|
gameFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||||
|
gameFrame.setSize(1040, 1000);
|
||||||
|
gameFrame.setLayout(new BorderLayout());
|
||||||
|
|
||||||
|
// Label de bienvenue
|
||||||
|
JLabel label = new JLabel("Bienvenue dans le jeu !");
|
||||||
|
label.setFont(new Font("Arial", Font.BOLD, 28));
|
||||||
|
label.setHorizontalAlignment(SwingConstants.CENTER);
|
||||||
|
|
||||||
|
// Ajouter le label et afficher la fenêtre
|
||||||
|
gameFrame.add(label, BorderLayout.CENTER);
|
||||||
|
gameFrame.setVisible(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
48
src/fr/iut/Projet/Display.java
Normal file
48
src/fr/iut/Projet/Display.java
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
package fr.iut.Projet;
|
||||||
|
|
||||||
|
import javax.swing.*;
|
||||||
|
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 {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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) {
|
||||||
|
// Création de la fenêtre principale
|
||||||
|
JFrame frame = new JFrame("Hanging Man");
|
||||||
|
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||||
|
frame.setSize(1040, 1000);
|
||||||
|
frame.setLayout(new BoxLayout(frame.getContentPane(), BoxLayout.Y_AXIS));
|
||||||
|
|
||||||
|
// Titre du jeu
|
||||||
|
JLabel text = new JLabel("Hanging Man");
|
||||||
|
text.setAlignmentX(Component.CENTER_ALIGNMENT);
|
||||||
|
text.setFont(new Font("Arial", Font.BOLD, 70));
|
||||||
|
|
||||||
|
// Bouton Play
|
||||||
|
JButton play = new JButton("Play");
|
||||||
|
play.setAlignmentX(Component.CENTER_ALIGNMENT);
|
||||||
|
play.setPreferredSize(new Dimension(300, 100));
|
||||||
|
play.setMaximumSize(new Dimension(300, 150));
|
||||||
|
play.setFont(new Font("Arial", Font.PLAIN, 36));
|
||||||
|
|
||||||
|
// Listener séparé pour gérer le clic sur Play
|
||||||
|
play.addActionListener(new PlayButtonListener(frame));
|
||||||
|
|
||||||
|
// Ajouter les composants avec de l'espace
|
||||||
|
frame.add(Box.createVerticalGlue());
|
||||||
|
frame.add(text);
|
||||||
|
frame.add(Box.createVerticalStrut(30));
|
||||||
|
frame.add(play);
|
||||||
|
frame.add(Box.createVerticalGlue());
|
||||||
|
|
||||||
|
// Affichage de la fenêtre
|
||||||
|
frame.setVisible(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
35
src/fr/iut/Projet/PlayButtonListener.java
Normal file
35
src/fr/iut/Projet/PlayButtonListener.java
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
package fr.iut.Projet;
|
||||||
|
|
||||||
|
import javax.swing.*;
|
||||||
|
import java.awt.event.ActionEvent;
|
||||||
|
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 {
|
||||||
|
|
||||||
|
/** Référence à la fenêtre principale du menu */
|
||||||
|
private JFrame parentFrame;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructeur de PlayButtonListener.
|
||||||
|
* @param frame La fenêtre principale à fermer après ouverture du jeu
|
||||||
|
*/
|
||||||
|
public PlayButtonListener(JFrame 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
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
new Action(); // Ouvre la fenêtre du jeu
|
||||||
|
parentFrame.dispose(); // Ferme la fenêtre principale
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user