diff --git a/Ecriture.java b/Ecriture.java new file mode 100644 index 0000000..8aaa703 --- /dev/null +++ b/Ecriture.java @@ -0,0 +1,40 @@ +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; + +import javax.swing.JFileChooser; +import javax.swing.JOptionPane; +import javax.swing.filechooser.FileNameExtensionFilter; + +public class Ecriture { + + public static void main(String[] args) { + Ecriture enregistreur = new Ecriture(); + enregistreur.enregistrerFichier(); + } + + public void enregistrerFichier() { + JFileChooser chooser = new JFileChooser(); + FileNameExtensionFilter filter = new FileNameExtensionFilter( + "Fichiers .lab", "lab"); + chooser.setFileFilter(filter); + int returnVal = chooser.showSaveDialog(null); + if(returnVal == JFileChooser.APPROVE_OPTION) { + String nomFichier = chooser.getSelectedFile().getName(); + if(!nomFichier.endsWith(".lab")) { + nomFichier += ".lab"; + } + String contenu = "Contenu du fichier .lab"; + File fichier = chooser.getSelectedFile(); + try { + BufferedWriter writer = new BufferedWriter(new FileWriter(fichier)); + writer.write(contenu); + writer.close(); + JOptionPane.showMessageDialog(null, "Le fichier a été enregistré avec succès"); + } catch (IOException e) { + JOptionPane.showMessageDialog(null, "Une erreur est survenue lors de l'enregistrement du fichier"); + } + } + } +} diff --git a/Exporter.java b/Exporter.java new file mode 100644 index 0000000..0fcc6bb --- /dev/null +++ b/Exporter.java @@ -0,0 +1,41 @@ +import java.awt.*; +import javax.swing.*; + +public class Exporter extends Fenetre{ + private boolean[][] cetteGrille; + private Cellules[][] grilleCellules; + private int cetteTaille; + + private JFrame fenetreGrille; + private JFrame fenetreModif; + + public Exporter(boolean[][] uneGrille, Cellules[][] uneGrilleCell, int uneTaille, JFrame fenetreG, JFrame fenetreM){ + this.cetteGrille = uneGrille; + this.grilleCellules = uneGrilleCell; + this.cetteTaille = uneTaille; + + this.fenetreGrille = fenetreG; + this.fenetreModif = fenetreM; + + this.fenetre.setSize(500,100); + this.fenetre.setTitle("Voulez vous enregistrer votre grille ?"); + + JPanel cePanel = new JPanel(); + FlowLayout gestionnaire2 = new FlowLayout(FlowLayout.CENTER); + cePanel.setLayout(gestionnaire2); + cePanel.setBackground(Color.CYAN); + + JButton unButton0 = new JButton("Sauvegarder"); + JButton unButton1 = new JButton("Passer"); + + cePanel.add(unButton0); + cePanel.add(unButton1); + + GestionExporter cesOptions = new GestionExporter(this.cetteGrille, this.grilleCellules, this.cetteTaille, this.fenetreGrille, this.fenetreModif, this.fenetre); + unButton0.addActionListener(cesOptions); + unButton1.addActionListener(cesOptions); + + this.fenetre.add(cePanel); + this.fenetre.setVisible(true); + } +} \ No newline at end of file diff --git a/FenetreRndmGrille.java b/FenetreRndmGrille.java index d8810f4..d439241 100644 --- a/FenetreRndmGrille.java +++ b/FenetreRndmGrille.java @@ -15,11 +15,15 @@ public class FenetreRndmGrille extends Fenetre{ private int[] tabCouleur; private boolean[][] grille; + private Cellules[][] grilleCellules; + + private Modifications modif; public FenetreRndmGrille(int taille){ super(); this.taille = taille; this.grille = new boolean[this.taille][this.taille]; + this.grilleCellules = new Cellules[this.taille][this.taille]; this.tabCouleur = new int[] {1, 1}; } @@ -31,9 +35,9 @@ public class FenetreRndmGrille extends Fenetre{ GridLayout gestionnaire = new GridLayout(this.taille,this.taille); this.fenetre.setLayout(gestionnaire); - PanneauModification interfacePanel = new PanneauModification(this.grille, this.taille); + PanneauModification interfacePanel = new PanneauModification(this.grille, this.taille, this.grilleCellules, this.fenetre); interfacePanel.SetUp(); - + /* ======= Valeurs aléatoire pour l'entre et la sortie ========== */ Random rand = new Random(); @@ -46,8 +50,6 @@ public class FenetreRndmGrille extends Fenetre{ } } - /* =============================================================== */ - int compteur=0; for(int i=0; i