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-05-23 12:56:40 +02:00
|
|
|
private JLabel showLines;
|
|
|
|
private JLabel showColumns;
|
|
|
|
private JLabel showMines;
|
|
|
|
|
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");
|
2022-05-23 16:10:45 +02:00
|
|
|
Dimension frameSize = new Dimension (screenSize.width *2/5,screenSize.height * 2/3);
|
2022-05-23 13:45:34 +02:00
|
|
|
this.setSize(frameSize);
|
2022-05-23 16:10:45 +02:00
|
|
|
this.setLocation(screenSize.width * 3/10, screenSize.height * 1/6);
|
2022-05-21 17:30:12 +02:00
|
|
|
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
|
|
|
this.setLayout(null);
|
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 23:01:08 +02:00
|
|
|
this.sliderLignes = new JSlider(4,30,20);
|
|
|
|
this.sliderColonnes = new JSlider(4,30,25);
|
|
|
|
this.sliderMines = new JSlider(1,900, 50);
|
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-23 16:10:45 +02:00
|
|
|
sliderLignes.setBounds(frameSize.width*3/5, frameSize.height*6/15, frameSize.width/3, frameSize.height/20);
|
|
|
|
sliderColonnes.setBounds(frameSize.width*3/5, frameSize.height*8/15, frameSize.width/3, frameSize.height/20);
|
|
|
|
sliderMines.setBounds(frameSize.width*3/5, frameSize.height*10/15, frameSize.width/3, frameSize.height/20);
|
2022-05-23 13:45:34 +02:00
|
|
|
|
2022-05-21 17:30:12 +02:00
|
|
|
this.add(sliderLignes);
|
|
|
|
this.add(sliderColonnes);
|
|
|
|
this.add(sliderMines);
|
2022-05-23 12:56:40 +02:00
|
|
|
|
|
|
|
this.showLines= new JLabel("Lignes : 20");
|
|
|
|
this.showColumns= new JLabel("Colonnes : 25");
|
|
|
|
this.showMines= new JLabel("Mines : 50");
|
|
|
|
|
2022-05-23 16:10:45 +02:00
|
|
|
this.showLines.setBounds(frameSize.width*3/5, frameSize.height*5/15, frameSize.width/3, frameSize.height/20);
|
|
|
|
this.showColumns.setBounds(frameSize.width*3/5, frameSize.height*7/15, frameSize.width/3, frameSize.height/20);
|
|
|
|
this.showMines.setBounds(frameSize.width*3/5, frameSize.height*9/15, frameSize.width/3, frameSize.height/20);
|
2022-05-23 13:45:34 +02:00
|
|
|
|
2022-05-23 12:56:40 +02:00
|
|
|
this.add(showLines);
|
|
|
|
this.add(showColumns);
|
|
|
|
this.add(showMines);
|
2022-05-21 17:03:31 +02:00
|
|
|
|
|
|
|
JButton newGame = new JButton("New Game");
|
|
|
|
newGame.addActionListener(new NewGameListener(this));
|
|
|
|
|
2022-05-23 16:10:45 +02:00
|
|
|
newGame.setBounds(frameSize.width*3/5, frameSize.height*12/15, frameSize.width/5, frameSize.height/15);;
|
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);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2022-05-23 16:10:45 +02:00
|
|
|
exit.setBounds(frameSize.width/10, frameSize.height*12/15, frameSize.width/5, frameSize.height/15);
|
2022-05-21 17:30:12 +02:00
|
|
|
this.add(exit);
|
2022-05-21 17:03:31 +02:00
|
|
|
|
2022-05-21 17:53:19 +02:00
|
|
|
//TODO : Bouton charger
|
2022-05-23 16:10:45 +02:00
|
|
|
this.setResizable(false);
|
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
|
|
|
|
2022-05-23 12:56:40 +02:00
|
|
|
// Méthode pour récupérer les valeurs des paramètres et les afficher à l'écran
|
2022-05-21 17:03:31 +02:00
|
|
|
public void setSettings(int settingToSet, int settingValue){
|
|
|
|
if (settingToSet==0){
|
|
|
|
this.lignes=settingValue;
|
2022-05-23 12:56:40 +02:00
|
|
|
showLines.setText("Lignes : "+settingValue);
|
2022-05-21 17:03:31 +02:00
|
|
|
} else if (settingToSet==1){
|
|
|
|
this.colonnes=settingValue;
|
2022-05-23 12:56:40 +02:00
|
|
|
showColumns.setText("Colonnes : "+settingValue);
|
2022-05-21 17:03:31 +02:00
|
|
|
} else if (settingToSet==2){
|
|
|
|
this.mines=settingValue;
|
2022-05-23 12:56:40 +02:00
|
|
|
showMines.setText("Mines : "+settingValue);
|
2022-05-21 17:03:31 +02:00
|
|
|
}
|
|
|
|
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
|
|
|
}
|