2022-04-25 17:10:55 +02:00
|
|
|
import javax.swing.*;
|
2022-05-21 17:30:12 +02:00
|
|
|
import java.awt.event.*;
|
2022-05-24 23:41:34 +02:00
|
|
|
import java.io.File;
|
2022-04-25 17:10:55 +02:00
|
|
|
import java.awt.*;
|
2022-05-25 10:42:04 +02:00
|
|
|
/**
|
|
|
|
* La classe <code>FrameMenu</code> correspond à une fenêtre de menu,
|
|
|
|
* elle l'affiche et régit aux directives de l'utilisateur (Jouer, Charger, Quitter)
|
|
|
|
* @version 1.1
|
|
|
|
* @author Kayyissa Haïssous
|
|
|
|
*/
|
2022-05-21 17:30:12 +02:00
|
|
|
public class FrameMenu extends JFrame{
|
2022-05-25 10:42:04 +02:00
|
|
|
/**
|
|
|
|
* Nombre de lignes pour la partie à lancer
|
|
|
|
*/
|
2022-05-20 13:39:53 +02:00
|
|
|
private int lignes;
|
2022-05-25 10:42:04 +02:00
|
|
|
/**
|
|
|
|
* Nombre de colonnes pour la partie à lancer
|
|
|
|
*/
|
2022-05-20 13:39:53 +02:00
|
|
|
private int colonnes;
|
2022-05-25 10:42:04 +02:00
|
|
|
/**
|
|
|
|
* Nombre de mines pour la partie à lancer
|
|
|
|
*/
|
2022-05-20 13:39:53 +02:00
|
|
|
private int mines;
|
2022-05-25 10:42:04 +02:00
|
|
|
/**
|
|
|
|
* JSlider qui permet de choisir le nombre de lignes
|
|
|
|
*/
|
2022-05-21 17:03:31 +02:00
|
|
|
private JSlider sliderLignes;
|
2022-05-25 10:42:04 +02:00
|
|
|
/**
|
|
|
|
* JSlider qui permet de choisir le nombre de colonnes
|
|
|
|
*/
|
2022-05-21 17:03:31 +02:00
|
|
|
private JSlider sliderColonnes;
|
2022-05-25 10:42:04 +02:00
|
|
|
/**
|
|
|
|
* JSlider qui permet de choisir le nombre de mines
|
|
|
|
*/
|
2022-05-21 17:03:31 +02:00
|
|
|
private JSlider sliderMines;
|
2022-05-25 10:42:04 +02:00
|
|
|
/**
|
|
|
|
* JLabel qui permet d'afficher en temps réel le nombre de lignes
|
|
|
|
*/
|
2022-05-23 12:56:40 +02:00
|
|
|
private JLabel showLines;
|
2022-05-25 10:42:04 +02:00
|
|
|
/**
|
|
|
|
* JLabel qui permet d'afficher en temps réel le nombre de colonnes
|
|
|
|
*/
|
2022-05-23 12:56:40 +02:00
|
|
|
private JLabel showColumns;
|
2022-05-25 10:42:04 +02:00
|
|
|
/**
|
|
|
|
* JLabel qui permet d'afficher en temps réel le nombre de mines
|
|
|
|
*/
|
2022-05-23 12:56:40 +02:00
|
|
|
private JLabel showMines;
|
2022-05-25 10:42:04 +02:00
|
|
|
/**
|
|
|
|
* JButton pour charger une éventuelle sauvegarde
|
|
|
|
*/
|
2022-05-25 08:47:55 +02:00
|
|
|
private JButton charger;
|
2022-05-23 12:56:40 +02:00
|
|
|
|
2022-05-25 10:42:04 +02:00
|
|
|
/**
|
|
|
|
* Constructeur destiné à la création et l'affichage de la fenêtre de menu
|
|
|
|
*/
|
2022-04-25 17:10:55 +02:00
|
|
|
public FrameMenu() {
|
2022-05-23 23:02:19 +02:00
|
|
|
super();
|
2022-04-25 17:10:55 +02:00
|
|
|
|
|
|
|
// 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-23 23:02:19 +02:00
|
|
|
this.getContentPane().setBackground( new Color(0, 236, 96));
|
2022-05-18 14:42:02 +02:00
|
|
|
|
2022-05-23 23:02:19 +02:00
|
|
|
// Ajout du titre
|
|
|
|
JLabel titre = new JLabel("Démineur");
|
|
|
|
titre.setFont(new Font("Rockwell", Font.PLAIN, 45));
|
|
|
|
titre.setBounds((frameSize.width/3), frameSize.height/15,frameSize.width/2,frameSize.height*2/15);
|
|
|
|
this.add(titre);
|
2022-05-18 14:42:02 +02:00
|
|
|
|
2022-05-25 10:42:04 +02:00
|
|
|
// On créer les Jsliders et les JLabel qui afficheront leur valeur
|
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 23:02:19 +02:00
|
|
|
sliderLignes.setBounds(frameSize.width/3, frameSize.height*5/15, frameSize.width/3, frameSize.height/20);
|
|
|
|
sliderColonnes.setBounds(frameSize.width/3, frameSize.height*7/15, frameSize.width/3, frameSize.height/20);
|
|
|
|
sliderMines.setBounds(frameSize.width/3, frameSize.height*9/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 23:02:19 +02:00
|
|
|
this.showLines.setBounds(frameSize.width/3, frameSize.height*4/15, frameSize.width/3, frameSize.height/20);
|
|
|
|
this.showColumns.setBounds(frameSize.width/3, frameSize.height*6/15, frameSize.width/3, frameSize.height/20);
|
|
|
|
this.showMines.setBounds(frameSize.width/3, frameSize.height*8/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
|
|
|
|
2022-05-25 10:42:04 +02:00
|
|
|
// On créer les boutons Jouer, quitter et si une save existe, charger
|
2022-05-23 19:32:09 +02:00
|
|
|
JButton newGame = new JButton("Jouer");
|
2022-05-21 17:03:31 +02:00
|
|
|
newGame.addActionListener(new NewGameListener(this));
|
|
|
|
|
2022-05-24 23:41:34 +02:00
|
|
|
newGame.setBounds(frameSize.width*7/10, 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");
|
2022-05-25 10:42:04 +02:00
|
|
|
exit.addActionListener(new ActionListener() {
|
2022-05-21 17:30:12 +02:00
|
|
|
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-24 23:41:34 +02:00
|
|
|
|
|
|
|
File save = new File("Save.txt");
|
|
|
|
if(save.exists()){
|
2022-05-25 08:47:55 +02:00
|
|
|
charger = new JButton("Charger");
|
2022-05-24 23:41:34 +02:00
|
|
|
charger.addActionListener(new Chargement(this));
|
|
|
|
charger.setBounds(frameSize.width*4/10, frameSize.height*12/15, frameSize.width/5, frameSize.height/15);
|
|
|
|
this.add(charger);
|
|
|
|
}
|
2022-05-21 17:03:31 +02:00
|
|
|
|
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-25 10:42:04 +02:00
|
|
|
/**
|
|
|
|
* Méthode pour récupérer les valeurs des paramètres et les afficher à l'écran
|
|
|
|
* @param settingToSet Le paramètre qui doit être changé
|
|
|
|
* @param settingValue La nouvelle valeur à donner au paramètre
|
|
|
|
*/
|
|
|
|
public void setSettings(int settingToSet, int settingValue) {
|
2022-05-21 17:03:31 +02:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2022-05-25 10:42:04 +02:00
|
|
|
/**
|
|
|
|
* Renvoie les valeurs des paramètres
|
|
|
|
* @return les paramètres pour une nouvelle partie
|
|
|
|
*/
|
|
|
|
public int[] getSettings() {
|
2022-05-21 17:03:31 +02:00
|
|
|
int[] settings = new int[3];
|
|
|
|
settings[0]=this.lignes;
|
|
|
|
settings[1]=this.colonnes;
|
|
|
|
settings[2]=this.mines;
|
|
|
|
return settings;
|
|
|
|
}
|
2022-05-25 08:47:55 +02:00
|
|
|
|
2022-05-25 10:42:04 +02:00
|
|
|
/**
|
|
|
|
* Méthode pour supprimer le bouton charger après avoir chargé une partie
|
|
|
|
*/
|
|
|
|
public void deleteCharger() {
|
2022-05-25 08:47:55 +02:00
|
|
|
this.remove(this.charger);
|
|
|
|
}
|
2022-04-25 17:10:55 +02:00
|
|
|
}
|