save nickel fenetre+bouton
This commit is contained in:
parent
c23cf8c655
commit
32d6ad2eb3
BIN
Avancee.odt
BIN
Avancee.odt
Binary file not shown.
@ -5,6 +5,7 @@ public class Banniere extends JPanel {
|
|||||||
private FrameJeu fenetre;
|
private FrameJeu fenetre;
|
||||||
private FrameMenu menu;
|
private FrameMenu menu;
|
||||||
private JButton save;
|
private JButton save;
|
||||||
|
private JLabel mines;
|
||||||
// Définition du constructeur
|
// Définition du constructeur
|
||||||
public Banniere(int mines, FrameJeu fenetre, FrameMenu menu, Grille grille) {
|
public Banniere(int mines, FrameJeu fenetre, FrameMenu menu, Grille grille) {
|
||||||
super();
|
super();
|
||||||
@ -16,6 +17,11 @@ public class Banniere extends JPanel {
|
|||||||
this.setBackground(new Color(0, 236, 96));
|
this.setBackground(new Color(0, 236, 96));
|
||||||
this.setLayout(new BorderLayout());
|
this.setLayout(new BorderLayout());
|
||||||
|
|
||||||
|
// Compteur de mines restantes
|
||||||
|
|
||||||
|
this.mines= new JLabel();
|
||||||
|
this.add(this.mines, BorderLayout.NORTH);
|
||||||
|
|
||||||
// Bouton pour sauver et quitter
|
// Bouton pour sauver et quitter
|
||||||
this.save = new JButton("Sauver et quitter");
|
this.save = new JButton("Sauver et quitter");
|
||||||
save.addActionListener(new SaveListener(grille, fenetre));
|
save.addActionListener(new SaveListener(grille, fenetre));
|
||||||
@ -24,8 +30,7 @@ public class Banniere extends JPanel {
|
|||||||
|
|
||||||
// Méthode pour afficher le nombre de mines restantes
|
// Méthode pour afficher le nombre de mines restantes
|
||||||
public void setMinesLeft(int minesLeft) {
|
public void setMinesLeft(int minesLeft) {
|
||||||
JLabel mines = new JLabel("Mines restantes : "+Integer.toString(minesLeft));
|
this.mines.setText("Mines restantes : "+Integer.toString(minesLeft));
|
||||||
this.add(mines, BorderLayout.NORTH);
|
|
||||||
this.repaint();
|
this.repaint();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
16
Chargement.java
Normal file
16
Chargement.java
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
import java.awt.event.*;
|
||||||
|
public class Chargement implements ActionListener {
|
||||||
|
private FrameMenu menu;
|
||||||
|
public Chargement(FrameMenu menu){
|
||||||
|
this.menu=menu;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
this.menu.dispose();
|
||||||
|
SaveManager saveManager = new SaveManager();
|
||||||
|
SaveManager.SaveData donnees = saveManager.load("Save.txt");
|
||||||
|
System.out.println(donnees);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -1,5 +1,6 @@
|
|||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
import java.awt.event.*;
|
import java.awt.event.*;
|
||||||
|
import java.io.File;
|
||||||
import java.awt.*;
|
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...)
|
// Cette classe à pour but d'afficher un menu et de réagir aux directives de l'utilisateur (lancer le jeu, le quitter...)
|
||||||
@ -71,7 +72,7 @@ public class FrameMenu extends JFrame{
|
|||||||
JButton newGame = new JButton("Jouer");
|
JButton newGame = new JButton("Jouer");
|
||||||
newGame.addActionListener(new NewGameListener(this));
|
newGame.addActionListener(new NewGameListener(this));
|
||||||
|
|
||||||
newGame.setBounds(frameSize.width*10/15, frameSize.height*12/15, frameSize.width/5, frameSize.height/15);;
|
newGame.setBounds(frameSize.width*7/10, frameSize.height*12/15, frameSize.width/5, frameSize.height/15);;
|
||||||
this.add(newGame);
|
this.add(newGame);
|
||||||
|
|
||||||
JButton exit = new JButton("Quitter");
|
JButton exit = new JButton("Quitter");
|
||||||
@ -84,7 +85,14 @@ public class FrameMenu extends JFrame{
|
|||||||
exit.setBounds(frameSize.width/10, frameSize.height*12/15, frameSize.width/5, frameSize.height/15);
|
exit.setBounds(frameSize.width/10, frameSize.height*12/15, frameSize.width/5, frameSize.height/15);
|
||||||
this.add(exit);
|
this.add(exit);
|
||||||
|
|
||||||
//TODO : Bouton charger
|
File save = new File("Save.txt");
|
||||||
|
if(save.exists()){
|
||||||
|
JButton charger = new JButton("Charger");
|
||||||
|
charger.addActionListener(new Chargement(this));
|
||||||
|
charger.setBounds(frameSize.width*4/10, frameSize.height*12/15, frameSize.width/5, frameSize.height/15);
|
||||||
|
this.add(charger);
|
||||||
|
}
|
||||||
|
|
||||||
this.setResizable(false);
|
this.setResizable(false);
|
||||||
this.setVisible(true);
|
this.setVisible(true);
|
||||||
}
|
}
|
||||||
|
@ -10,6 +10,8 @@ public class MenuListener implements ActionListener{
|
|||||||
@Override
|
@Override
|
||||||
public void actionPerformed(ActionEvent event){
|
public void actionPerformed(ActionEvent event){
|
||||||
this.menu.setVisible(true);
|
this.menu.setVisible(true);
|
||||||
|
WindowListener[] wl= this.fenetre.getWindowListeners();
|
||||||
|
this.fenetre.removeWindowListener(wl[0]);
|
||||||
this.fenetre.dispose();
|
this.fenetre.dispose();
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -13,7 +13,6 @@ public class SaveAndCloseListener implements WindowListener{
|
|||||||
public void windowClosing(WindowEvent e) {
|
public void windowClosing(WindowEvent e) {
|
||||||
SaveManager saveManager = new SaveManager();
|
SaveManager saveManager = new SaveManager();
|
||||||
saveManager.save(this.grille, "Save.txt");
|
saveManager.save(this.grille, "Save.txt");
|
||||||
SaveManager.SaveData donnees = saveManager.load("Save.txt");
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -11,7 +11,6 @@ public class SaveListener implements ActionListener {
|
|||||||
public void actionPerformed(ActionEvent event){
|
public void actionPerformed(ActionEvent event){
|
||||||
SaveManager saveManager = new SaveManager();
|
SaveManager saveManager = new SaveManager();
|
||||||
saveManager.save(this.grille, "Save.txt");
|
saveManager.save(this.grille, "Save.txt");
|
||||||
SaveManager.SaveData donnees = saveManager.load("Save.txt");
|
|
||||||
this.fenetre.dispose();
|
this.fenetre.dispose();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -49,6 +49,9 @@ public class SaveManager {
|
|||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
File save = new File(nomFichier);
|
||||||
|
save.delete();
|
||||||
|
|
||||||
toRet.cases=toReturn;
|
toRet.cases=toReturn;
|
||||||
toRet.taille=dimension;
|
toRet.taille=dimension;
|
||||||
return toRet;
|
return toRet;
|
||||||
|
@ -1,9 +0,0 @@
|
|||||||
public class SaveTester {
|
|
||||||
public static void main(String[] args) {
|
|
||||||
Grille grille = new Grille(10,10,10, null, null);
|
|
||||||
SaveManager saveManager = new SaveManager();
|
|
||||||
|
|
||||||
saveManager.save(grille, "test_sauvegarde.txt");
|
|
||||||
SaveManager.SaveData donnees = saveManager.load("test_sauvegarde.txt");
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user