Revision de partie du code + transition des donnés revue
This commit is contained in:
parent
290873e1dc
commit
5d581d82b7
40
Ecriture.java
Normal file
40
Ecriture.java
Normal file
@ -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");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
41
Exporter.java
Normal file
41
Exporter.java
Normal file
@ -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);
|
||||
}
|
||||
}
|
@ -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<taille; i++){
|
||||
@ -60,39 +62,41 @@ public class FenetreRndmGrille extends Fenetre{
|
||||
grille[i][j] = true;
|
||||
}
|
||||
|
||||
Modifications modif = new Modifications(interfacePanel, grille,this.tabCouleur);
|
||||
this.modif = new Modifications(interfacePanel, grille,this.tabCouleur);
|
||||
|
||||
if(compteur == ValeurEntre)
|
||||
{
|
||||
Cellules cellules = new Cellules(i,j, ENTREE);
|
||||
this.fenetre.add(cellules);
|
||||
cellules.addMouseListener(modif);
|
||||
grilleCellules[i][j] = cellules;
|
||||
}
|
||||
else if(compteur == ValeurSortie)
|
||||
{
|
||||
Cellules cellules = new Cellules(i, j, SORTIE);
|
||||
this.fenetre.add(cellules);
|
||||
cellules.addMouseListener(modif);
|
||||
grilleCellules[i][j] = cellules;
|
||||
}
|
||||
else if(grille[i][j] == true)
|
||||
{
|
||||
Cellules cellules = new Cellules(i, j, COULOIR);
|
||||
this.fenetre.add(cellules);
|
||||
cellules.addMouseListener(modif);
|
||||
grilleCellules[i][j] = cellules;
|
||||
}
|
||||
else
|
||||
{
|
||||
Cellules cellules = new Cellules(i, j, MUR);
|
||||
this.fenetre.add(cellules);
|
||||
cellules.addMouseListener(modif);
|
||||
grilleCellules[i][j] = cellules;
|
||||
}
|
||||
|
||||
this.tabCouleur = modif.getGateState();
|
||||
compteur++;
|
||||
}
|
||||
}
|
||||
/*System.out.print("\n");
|
||||
PrintGrille afficGrille = new PrintGrille(grille, taille);*/
|
||||
this.fenetre.setVisible(true);
|
||||
}
|
||||
}
|
||||
|
@ -9,13 +9,14 @@ public class FenetreVideGrille extends Fenetre{
|
||||
private int taille;
|
||||
|
||||
private boolean[][] grille;
|
||||
private Cellules[][] grilleCellules;
|
||||
private int[] tabCouleur;
|
||||
|
||||
public FenetreVideGrille(int taille){
|
||||
super();
|
||||
this.taille = taille;
|
||||
this.grille = new boolean[this.taille][this.taille];
|
||||
this.tabCouleur = new int[] {0, 0};
|
||||
this.grilleCellules = new Cellules[this.taille][this.taille];
|
||||
}
|
||||
|
||||
public void videGrille(){
|
||||
@ -26,7 +27,7 @@ public class FenetreVideGrille 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();
|
||||
|
||||
/* =============================================================== */
|
||||
|
@ -3,11 +3,9 @@ import java.io.File;
|
||||
|
||||
public class FileImport {
|
||||
private String ce_chemin;
|
||||
|
||||
public FileImport(){
|
||||
this.ce_chemin = "";
|
||||
};
|
||||
|
||||
public String Parcours(){
|
||||
JFileChooser fileChooser = new JFileChooser();
|
||||
int option = fileChooser.showOpenDialog(null);
|
||||
@ -17,7 +15,6 @@ public class FileImport {
|
||||
} else {
|
||||
System.out.println("No file selected");
|
||||
}
|
||||
|
||||
return this.ce_chemin;
|
||||
}
|
||||
}
|
||||
}
|
38
GestionExporter.java
Normal file
38
GestionExporter.java
Normal file
@ -0,0 +1,38 @@
|
||||
import java.awt.event.*;
|
||||
import javax.swing.*;
|
||||
|
||||
public class GestionExporter implements ActionListener{
|
||||
|
||||
private String Reponses1="Sauvegarder", Reponses2="Passer";
|
||||
private String cet_event;
|
||||
private boolean[][] cetteGrille;
|
||||
private Cellules[][] grilleCellules;
|
||||
private int cetteTaille;
|
||||
|
||||
private JFrame frameGrille;
|
||||
private JFrame frameModif;
|
||||
private JFrame framePopup;
|
||||
|
||||
public GestionExporter(boolean[][] uneGrille, Cellules[][] uneGrilleCell , int uneTaille, JFrame frameG, JFrame frameM, JFrame frameP){
|
||||
this.cetteGrille=uneGrille;
|
||||
this.cetteTaille=uneTaille;
|
||||
this.grilleCellules=uneGrilleCell;
|
||||
|
||||
this.frameGrille = frameG;
|
||||
this.frameModif = frameM;
|
||||
this.framePopup = frameP;
|
||||
}
|
||||
|
||||
public void actionPerformed(ActionEvent e){
|
||||
this.cet_event=e.getActionCommand();
|
||||
if (cet_event.equals(this.Reponses1)){
|
||||
System.out.println("Sauvegardeeeeeeeeeee");
|
||||
}
|
||||
else if (cet_event.equals(this.Reponses2)){
|
||||
this.frameGrille.dispose();
|
||||
this.frameModif.dispose();
|
||||
this.framePopup.dispose();
|
||||
System.out.println("tout a été fermé");
|
||||
}
|
||||
}
|
||||
}
|
@ -1,15 +1,23 @@
|
||||
import java.awt.event.*;
|
||||
import javax.swing.*;
|
||||
|
||||
public class GestionModif implements ActionListener{
|
||||
private String Reponses1="Quitter", Reponses2="Sauvegarder";
|
||||
private String Reponses1="Quitter", Reponses2="Suivant";
|
||||
private String cet_event;
|
||||
private boolean[][] cetteGrille;
|
||||
private Cellules[][] grilleCellules;
|
||||
private int cetteTaille;
|
||||
private PrintGrille affiche;
|
||||
|
||||
public GestionModif(boolean[][] uneGrille, int uneTaille){
|
||||
private JFrame cetteFrameGrille;
|
||||
private JFrame cetteFrameModif;
|
||||
|
||||
public GestionModif(boolean[][] uneGrille, Cellules[][] uneGrilleCell, int uneTaille, JFrame frameGrille, JFrame frameModif){
|
||||
this.cetteGrille=uneGrille;
|
||||
this.cetteTaille=uneTaille;
|
||||
this.affiche = new PrintGrille(this.cetteGrille, this.cetteTaille);
|
||||
this.grilleCellules=uneGrilleCell;
|
||||
|
||||
this.cetteFrameGrille = frameGrille;
|
||||
this.cetteFrameModif = frameModif;
|
||||
}
|
||||
|
||||
public void actionPerformed(ActionEvent e){
|
||||
@ -18,7 +26,7 @@ public class GestionModif implements ActionListener{
|
||||
System.exit(1);
|
||||
}
|
||||
else if (cet_event.equals(this.Reponses2)){
|
||||
this.affiche = new PrintGrille(this.cetteGrille, this.cetteTaille);
|
||||
Exporter newExport = new Exporter(this.cetteGrille, this.grilleCellules, this.cetteTaille, this.cetteFrameGrille, this.cetteFrameModif);
|
||||
}
|
||||
}
|
||||
}
|
15
Makefile
15
Makefile
@ -64,14 +64,18 @@ Modifications.class : Modifications.java ModificationsTab.class
|
||||
ModificationsTab.class : ModificationsTab.java Affichage.class
|
||||
${JC} ${JCFLAGS} ModificationsTab.java
|
||||
|
||||
GestionModif.class : GestionModif.java
|
||||
GestionModif.class : GestionModif.java Exporter.class
|
||||
${JC} ${JCFLAGS} GestionModif.java
|
||||
|
||||
Affichage.class : Affichage.java PrintGrille.class
|
||||
Affichage.class : Affichage.java outils.class
|
||||
${JC} ${JCFLAGS} Affichage.java
|
||||
|
||||
PrintGrille.class : PrintGrille.java
|
||||
${JC} ${JCFLAGS} PrintGrille.java
|
||||
Exporter.class : Exporter.java GestionExporter.class
|
||||
${JC} ${JCFLAGS} Exporter.java
|
||||
|
||||
GestionExporter.class : GestionExporter.java
|
||||
${JC} ${JCFLAGS} GestionExporter.java
|
||||
|
||||
# ================================
|
||||
|
||||
### REGLES OPTIONNELLES ###
|
||||
@ -82,6 +86,9 @@ run : Start.class
|
||||
clean :
|
||||
-rm -f *.class
|
||||
|
||||
nettoyer :
|
||||
rm .\*.class
|
||||
|
||||
mrproper : clean Start.class
|
||||
|
||||
### BUTS FACTICES ###
|
||||
|
@ -18,7 +18,7 @@ public class Modifications implements MouseListener {
|
||||
}
|
||||
|
||||
public int[] getGateState(){
|
||||
System.out.println("this.ceTab vaut : [0] : "+this.ceTab[0] + " et this.ceTab vaut : [1] :"+this.ceTab[1]);
|
||||
//System.out.println("this.ceTab vaut : [0] : "+this.ceTab[0] + " et this.ceTab vaut : [1] :"+this.ceTab[1]);
|
||||
return this.ceTab;
|
||||
}
|
||||
|
||||
|
@ -6,14 +6,21 @@ public class PanneauModification extends Fenetre {
|
||||
public JRadioButton radio3;
|
||||
|
||||
private boolean[][] cetteGrille;
|
||||
private Cellules[][] grilleCellules;
|
||||
private int cetteTaille;
|
||||
|
||||
private JFrame frameGrille;
|
||||
|
||||
public PanneauModification(boolean[][] uneGrille, int uneTaille){
|
||||
public PanneauModification(boolean[][] uneGrille, int uneTaille, Cellules[][] uneGrilleCell, JFrame uneFrame){
|
||||
super();
|
||||
this.fenetre.setSize(400, 600);
|
||||
this.fenetre.setLocation(1100, 200);
|
||||
this.grilleCellules = uneGrilleCell;
|
||||
this.cetteGrille=uneGrille;
|
||||
this.cetteTaille=uneTaille;
|
||||
this.frameGrille = uneFrame;
|
||||
|
||||
this.frameGrille = uneFrame;
|
||||
}
|
||||
|
||||
public void SetUp(){
|
||||
@ -35,7 +42,7 @@ public class PanneauModification extends Fenetre {
|
||||
|
||||
/*Création du deuxième panneau */
|
||||
JPanel un_Panel3 = new JPanel();
|
||||
JButton un_Button1 = new JButton("Sauvegarder");
|
||||
JButton un_Button1 = new JButton("Suivant");
|
||||
JPanel un_Panel4 = new JPanel();
|
||||
un_Panel4.add(un_Button1);
|
||||
un_Panel3.setBackground(Color.CYAN);
|
||||
@ -86,7 +93,7 @@ public class PanneauModification extends Fenetre {
|
||||
this.fenetre.add(un_Panel5, BorderLayout.CENTER);
|
||||
|
||||
/* Evenement */
|
||||
GestionModif cesOptions = new GestionModif(this.cetteGrille, this.cetteTaille);
|
||||
GestionModif cesOptions = new GestionModif(this.cetteGrille, this.grilleCellules, this.cetteTaille, this.frameGrille, this.fenetre);
|
||||
un_Button1.addActionListener(cesOptions);
|
||||
un_Button2.addActionListener(cesOptions);
|
||||
|
||||
|
3
PreEcriture.java
Normal file
3
PreEcriture.java
Normal file
@ -0,0 +1,3 @@
|
||||
public class PreEcriture {
|
||||
public PreEcriture(){}
|
||||
}
|
@ -1,11 +0,0 @@
|
||||
public class PrintGrille {
|
||||
public PrintGrille(boolean[][] tab, int taille){
|
||||
for(int i=0; i<taille; i++){
|
||||
for(int j=0; j<taille; j++){
|
||||
System.out.print(tab[i][j]+" ");
|
||||
}
|
||||
System.out.print("\n");
|
||||
}
|
||||
System.out.print("\n ------------ \n FIN \n");
|
||||
}
|
||||
}
|
15
Retournement.java
Normal file
15
Retournement.java
Normal file
@ -0,0 +1,15 @@
|
||||
public class Retournement {
|
||||
private int[] ceTableau;
|
||||
|
||||
public Retournement(int[] unTableau){
|
||||
this.ceTableau = unTableau;
|
||||
}
|
||||
|
||||
public void setModifyTab(int emplacementTab, int emplacementGrille){
|
||||
this.ceTableau[emplacementTab] = emplacementGrille;
|
||||
}
|
||||
|
||||
public int[] getValeurPorte(){
|
||||
return this.ceTableau;
|
||||
}
|
||||
}
|
28
outils.java
28
outils.java
@ -4,40 +4,52 @@ public class outils {
|
||||
|
||||
public static int[] reverse(int[] un_tableau) {
|
||||
int taille = un_tableau.length;
|
||||
|
||||
int[] cette_copie;
|
||||
cette_copie = new int[un_tableau.length];
|
||||
int compteur=taille;
|
||||
|
||||
for(int j=0; j<cette_copie.length; j++){
|
||||
cette_copie[j]=un_tableau[compteur-1];
|
||||
compteur--;
|
||||
}
|
||||
|
||||
return cette_copie;
|
||||
}
|
||||
|
||||
public static int[] concatenate(int[] first_tab, int[] tab_to_add){
|
||||
int taille = first_tab.length;
|
||||
|
||||
int[] tableau_temp = new int[taille+tab_to_add.length];
|
||||
int compteur = 0;
|
||||
|
||||
if(first_tab != null){
|
||||
for(int i=0;i<taille;i++){
|
||||
tableau_temp[compteur]=first_tab[i];
|
||||
compteur++;
|
||||
}
|
||||
}
|
||||
|
||||
if(tab_to_add != null){
|
||||
for(int i=0;i<tab_to_add.length;i++){
|
||||
tableau_temp[compteur]=tab_to_add[i];
|
||||
compteur++;
|
||||
}
|
||||
}
|
||||
|
||||
return tableau_temp;
|
||||
|
||||
}
|
||||
|
||||
public static void PrintGrille(boolean[][] leTableau, int saTaille){
|
||||
for(int i=0; i<saTaille; i++){
|
||||
for(int j=0; j<saTaille; j++){
|
||||
System.out.print(leTableau[i][j]+" ");
|
||||
}
|
||||
System.out.print("\n");
|
||||
}
|
||||
System.out.print("\n ------------ \n FIN \n");
|
||||
}
|
||||
|
||||
public static void PrintGrilleCell(Cellules[][] leTableau, int saTaille){
|
||||
for(int i=0; i<saTaille; i++){
|
||||
for(int j=0; j<saTaille; j++){
|
||||
System.out.print("Le type vaut : "+leTableau[i][j].getType()+" | ");
|
||||
}
|
||||
System.out.print("\n");
|
||||
}
|
||||
System.out.print("\n ------------ \n FIN \n");
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user