Mise à jour du gitignore et nettoyage du cache
This commit is contained in:
75
src/MenuPrincipal.java
Normal file
75
src/MenuPrincipal.java
Normal file
@@ -0,0 +1,75 @@
|
||||
package linea;
|
||||
|
||||
import java.awt.FlowLayout;
|
||||
import java.awt.GridLayout;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JOptionPane;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JTextField;
|
||||
import javax.swing.SwingConstants;
|
||||
|
||||
// Classe qui représente le menu principal du jeu (affiché au lancement).
|
||||
public class MenuPrincipal {
|
||||
|
||||
private JFrame fenetre;
|
||||
private Jeu jeu;
|
||||
private JTextField champPseudo;
|
||||
|
||||
public MenuPrincipal(JFrame fenetre, Jeu jeu) {
|
||||
this.fenetre = fenetre;
|
||||
this.jeu = jeu;
|
||||
}
|
||||
|
||||
// Construit et affiche le panneau du menu dans la fenêtre
|
||||
public void afficher(String pseudoActuel) {
|
||||
|
||||
JPanel panneau = new JPanel(new GridLayout(6, 1, 10, 10));
|
||||
|
||||
JLabel titre = new JLabel("LINEA", SwingConstants.CENTER);
|
||||
champPseudo = new JTextField(pseudoActuel, 15);
|
||||
|
||||
JButton boutonJouer = new JButton("Jouer");
|
||||
JButton boutonClassement = new JButton("Classement");
|
||||
JButton boutonQuitter = new JButton("Quitter");
|
||||
|
||||
boutonJouer.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
jeu.lancerPartie(champPseudo.getText());
|
||||
}
|
||||
});
|
||||
|
||||
boutonClassement.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
JOptionPane.showMessageDialog(fenetre, "TOP SCORES", "Classement", JOptionPane.INFORMATION_MESSAGE);
|
||||
}
|
||||
});
|
||||
|
||||
boutonQuitter.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
System.exit(0);
|
||||
}
|
||||
});
|
||||
|
||||
panneau.add(titre);
|
||||
panneau.add(champPseudo);
|
||||
panneau.add(boutonJouer);
|
||||
panneau.add(boutonClassement);
|
||||
panneau.add(boutonQuitter);
|
||||
|
||||
// panneau centré dans la fenêtre
|
||||
JPanel conteneur = new JPanel(new FlowLayout(FlowLayout.CENTER, 0, 150));
|
||||
conteneur.add(panneau);
|
||||
|
||||
fenetre.setContentPane(conteneur);
|
||||
fenetre.revalidate();
|
||||
fenetre.repaint();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user