2022-04-25 17:10:55 +02:00
|
|
|
import javax.swing.*;
|
2022-05-21 17:30:12 +02:00
|
|
|
import java.awt.event.*;
|
2022-04-25 17:10:55 +02:00
|
|
|
import java.awt.*;
|
|
|
|
|
|
|
|
// Cette classe à pour but d'afficher un menu et de réagir aux directives de l'utilisateur (lancer le jeu, le quitter...)
|
2022-05-21 17:30:12 +02:00
|
|
|
public class FrameMenu extends JFrame{
|
2022-05-20 13:39:53 +02:00
|
|
|
private int lignes;
|
|
|
|
private int colonnes;
|
|
|
|
private int mines;
|
2022-05-21 17:03:31 +02:00
|
|
|
private JSlider sliderLignes;
|
|
|
|
private JSlider sliderColonnes;
|
|
|
|
private JSlider sliderMines;
|
2022-04-25 17:10:55 +02:00
|
|
|
public FrameMenu() {
|
|
|
|
|
|
|
|
// On récupère les dimensions de l'écran pour adapter la taille de notre fenêtre
|
|
|
|
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
|
|
|
|
|
|
|
|
// On crée ensuite notre fenêtre
|
2022-05-21 17:30:12 +02:00
|
|
|
this.setTitle("Démineur - Menu");
|
|
|
|
this.setSize(screenSize.width * 3/5,screenSize.height * 2/3);
|
|
|
|
this.setLocation(screenSize.width * 1/5, screenSize.height * 1/6);
|
|
|
|
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
|
|
|
this.setLayout(null);
|
|
|
|
this.setLayout(new GridBagLayout());
|
2022-05-19 08:12:15 +02:00
|
|
|
GridBagConstraints miseEnPage = new GridBagConstraints();
|
2022-05-18 14:42:02 +02:00
|
|
|
|
|
|
|
|
2022-05-19 08:12:15 +02:00
|
|
|
// On créer les zones de textes de saisie
|
2022-05-21 17:03:31 +02:00
|
|
|
this.sliderLignes = new JSlider(4,30);
|
|
|
|
this.sliderColonnes = new JSlider(4,30);
|
2022-05-21 17:30:12 +02:00
|
|
|
this.sliderMines = new JSlider(1,900, 16);
|
2022-05-19 08:12:15 +02:00
|
|
|
|
2022-05-21 17:03:31 +02:00
|
|
|
sliderLignes.addChangeListener(new SettingsListener(0,this));
|
|
|
|
sliderColonnes.addChangeListener(new SettingsListener(1,this));
|
|
|
|
sliderMines.addChangeListener(new SettingsListener(2,this));
|
2022-05-19 08:12:15 +02:00
|
|
|
|
2022-05-20 13:39:53 +02:00
|
|
|
this.lignes=sliderLignes.getValue();
|
|
|
|
this.colonnes=sliderColonnes.getValue();
|
|
|
|
this.mines=sliderMines.getValue();
|
2022-05-21 17:03:31 +02:00
|
|
|
|
2022-05-21 17:30:12 +02:00
|
|
|
this.add(sliderLignes);
|
|
|
|
this.add(sliderColonnes);
|
|
|
|
this.add(sliderMines);
|
2022-05-21 17:03:31 +02:00
|
|
|
|
|
|
|
JButton newGame = new JButton("New Game");
|
|
|
|
newGame.addActionListener(new NewGameListener(this));
|
|
|
|
|
2022-05-21 17:30:12 +02:00
|
|
|
this.add(newGame);
|
|
|
|
|
|
|
|
JButton exit = new JButton("Quitter");
|
|
|
|
exit.addActionListener(new ActionListener(){
|
|
|
|
public void actionPerformed(ActionEvent e) {
|
|
|
|
System.exit(0);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
this.add(exit);
|
2022-05-21 17:03:31 +02:00
|
|
|
|
2022-05-21 17:53:19 +02:00
|
|
|
//TODO : Bouton charger
|
2022-05-21 17:30:12 +02:00
|
|
|
this.setVisible(true);
|
2022-04-25 17:10:55 +02:00
|
|
|
}
|
2022-05-21 17:03:31 +02:00
|
|
|
|
|
|
|
// Méthode pour récupérer les valeurs des paramètres
|
|
|
|
public void setSettings(int settingToSet, int settingValue){
|
|
|
|
if (settingToSet==0){
|
|
|
|
this.lignes=settingValue;
|
|
|
|
} else if (settingToSet==1){
|
|
|
|
this.colonnes=settingValue;
|
|
|
|
} else if (settingToSet==2){
|
|
|
|
this.mines=settingValue;
|
|
|
|
}
|
|
|
|
this.sliderMines.setMaximum(this.colonnes*this.lignes);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Methode pour connaître les paramètres de la partie
|
|
|
|
public int[] getSettings(){
|
|
|
|
int[] settings = new int[3];
|
|
|
|
settings[0]=this.lignes;
|
|
|
|
settings[1]=this.colonnes;
|
|
|
|
settings[2]=this.mines;
|
|
|
|
return settings;
|
|
|
|
}
|
2022-04-25 17:10:55 +02:00
|
|
|
}
|