From 5d581d82b791d00d64fbbda857f85a142f118a09 Mon Sep 17 00:00:00 2001 From: fauvet Date: Tue, 25 Apr 2023 11:42:59 +0200 Subject: [PATCH] =?UTF-8?q?Revision=20de=20partie=20du=20code=20+=20transi?= =?UTF-8?q?tion=20des=20donn=C3=A9s=20revue?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Ecriture.java | 40 +++++++++++++++++++++++++++++++++++++++ Exporter.java | 41 ++++++++++++++++++++++++++++++++++++++++ FenetreRndmGrille.java | 18 +++++++++++------- FenetreVideGrille.java | 5 +++-- FileImport.java | 5 +---- GestionExporter.java | 38 +++++++++++++++++++++++++++++++++++++ GestionModif.java | 18 +++++++++++++----- Makefile | 15 +++++++++++---- Modifications.java | 2 +- PanneauModification.java | 13 ++++++++++--- PreEcriture.java | 3 +++ PrintGrille.java | 11 ----------- Retournement.java | 15 +++++++++++++++ outils.java | 28 +++++++++++++++++++-------- 14 files changed, 207 insertions(+), 45 deletions(-) create mode 100644 Ecriture.java create mode 100644 Exporter.java create mode 100644 GestionExporter.java create mode 100644 PreEcriture.java delete mode 100644 PrintGrille.java create mode 100644 Retournement.java 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