diff --git a/EssaiChoixFichier.class b/EssaiChoixFichier.class deleted file mode 100644 index 3ef8064..0000000 Binary files a/EssaiChoixFichier.class and /dev/null differ diff --git a/EssaiChoixFichier.java b/EssaiChoixFichier.java deleted file mode 100644 index 09e1b5f..0000000 --- a/EssaiChoixFichier.java +++ /dev/null @@ -1,15 +0,0 @@ -import java.io.File; -import java.io.PrintWriter; -import java.io.FileWriter; -import java.io.IOException; -import javax.swing.JFileChooser; - -class EssaiChoixFichier { - public static void main(String[] arg) throws IOException { - JFileChooser dialogue = new JFileChooser(new File(".")); - - if (dialogue.showOpenDialog(null)==JFileChooser.APPROVE_OPTION) { - dialogue.getSelectedFile(); - } - } -} \ No newline at end of file diff --git a/Grilles.class b/Grilles.class new file mode 100644 index 0000000..10ec0fe Binary files /dev/null and b/Grilles.class differ diff --git a/Grilles.java b/Grilles.java new file mode 100644 index 0000000..ad4b88c --- /dev/null +++ b/Grilles.java @@ -0,0 +1,58 @@ +import javax.swing.*; +import java.awt.*; +import java.awt.event.*; +import java.io.*; +import java.io.File; +import java.io.PrintWriter; +import java.io.FileWriter; +import java.io.IOException; +import javax.swing.JFileChooser; +import javax.swing.filechooser.FileNameExtensionFilter; + +public class Grilles{ + public static void grilleExiste(String name) { + + int valeur[] = new int[9]; + int valeur_en_fin[][]= new int[9][9]; + + int valeur_actuelle=0; + int tabcase[][]= new int[9][9]; + try{ + FileInputStream fichier = new FileInputStream(name); + DataInputStream flux = new DataInputStream(fichier); + + try{ + for(int i=0; i<9; i++){ + valeur[i]=flux.readInt(); + } + flux.close(); + }catch(IOException e){ + System.out.println("Lecture fichier impossible"); + } + }catch(FileNotFoundException e){ + System.out.println("Fichier non trouvé"); + } + for(int i=0; i<9; i++){ + for(int j=8; j>=0; j--){ + valeur_actuelle=valeur[i]; + + valeur_actuelle=valeur_actuelle%10; + valeur[i]=(valeur[i]-valeur_actuelle)/10; + + valeur_en_fin[i][j]=valeur_actuelle; + System.out.print(valeur_actuelle); + } + valeur_actuelle=0; + } + } + + public static void grilleVide(int [][] g) { + int [][] remp = new int [9][9]; + for(int i = 0 ; i < 9 ; i++){ + for(int j = 0 ; j < 9 ; j++){ + remp[i][j] = 0; + } + } + g = remp; + } +} \ No newline at end of file diff --git a/Grilles/GrillesTest.gri b/Grilles/GrillesTest.gri new file mode 100644 index 0000000..6958f0c Binary files /dev/null and b/Grilles/GrillesTest.gri differ diff --git a/Main$2.class b/Main$2.class new file mode 100644 index 0000000..b37841e Binary files /dev/null and b/Main$2.class differ diff --git a/Main$3.class b/Main$3.class new file mode 100644 index 0000000..39cf51e Binary files /dev/null and b/Main$3.class differ diff --git a/MainCreation$1.class b/MainCreation$1.class index ddccb18..8765306 100644 Binary files a/MainCreation$1.class and b/MainCreation$1.class differ diff --git a/MainCreation$2.class b/MainCreation$2.class index c7899dd..2cf0aa6 100644 Binary files a/MainCreation$2.class and b/MainCreation$2.class differ diff --git a/MainCreation$3.class b/MainCreation$3.class index 4b6a0aa..2c18949 100644 Binary files a/MainCreation$3.class and b/MainCreation$3.class differ diff --git a/MainCreation.class b/MainCreation.class index 681e32f..15c4b61 100644 Binary files a/MainCreation.class and b/MainCreation.class differ diff --git a/MainCreation.java b/MainCreation.java index b775c66..1931fc8 100644 --- a/MainCreation.java +++ b/MainCreation.java @@ -1,15 +1,18 @@ import javax.swing.*; import java.awt.*; import java.awt.event.*; +import java.io.*; import java.io.File; import java.io.PrintWriter; import java.io.FileWriter; import java.io.IOException; import javax.swing.JFileChooser; +import javax.swing.filechooser.FileNameExtensionFilter; public class MainCreation { public static void main(String[] args) { - //Création de la fenetre de selection + int [][] grille = new int [9][9]; + //Création de la fenetre de selection + choix du dossier JFrame selF = new JFrame("Choix de résolution du Sudoku"); selF.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); selF.setSize(400, 200); @@ -34,34 +37,31 @@ public class MainCreation { @Override public void actionPerformed(ActionEvent e) { selF.dispose(); - int[][] grille = grilleVide(); - fenetreModification(grille, false); + Grilles.grilleVide(grille); + fenetreModification(grille); } }); grilleExiste.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { selF.dispose(); - int[][] grille = SudokuGenerator.readGridFromFile(); - fenetreModification(grille, false); + JFileChooser fichier = new JFileChooser(); + + FileNameExtensionFilter filter = new FileNameExtensionFilter("File grille","gri"); + fichier.setFileFilter(filter); + + File workingDirectory = new File(System.getProperty("user.dir")); + fichier.setCurrentDirectory(workingDirectory); + JPanel panneau = new JPanel(); + int valeur_de_retour = fichier.showOpenDialog(panneau); + if(valeur_de_retour == JFileChooser.APPROVE_OPTION) { + //Grilles.grilleExiste(fichier.getSelectedFile().getName()); + } } }); } - public static int[][] grilleVide() { - int[][] g = { - {0, 0, 0, 0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0, 0, 0, 0} - }; - return g; - } - private static void fenetreModification(int[][] grille, boolean modeAutomatique) { + + private static void fenetreModification(int[][] grille) { JFrame frame = new JFrame("Sudoku"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); SaisieGrille saisieGrille = new SaisieGrille(grille); // Utilisation de la classe SaisieGrille pour permettre la saisie des valeurs @@ -69,9 +69,17 @@ public class MainCreation { register.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e){ - JFileChooser dialogue = new JFileChooser(new File(".")); - if (dialogue.showOpenDialog(null)==JFileChooser.APPROVE_OPTION) { - dialogue.getSelectedFile(); + JFileChooser fileChooser = new JFileChooser(); + + FileNameExtensionFilter filter = new FileNameExtensionFilter("File grille","gri"); + fileChooser.setFileFilter(filter); + + File workingDirectory = new File(System.getProperty("user.dir")); + fileChooser.setCurrentDirectory(workingDirectory); + JPanel panneau = new JPanel(); + int valeur_de_retour = fileChooser.showOpenDialog(panneau); + if(valeur_de_retour == JFileChooser.APPROVE_OPTION) { + Register.sauvegarde(fileChooser.getSelectedFile().getName(), grille); } } }); diff --git a/Register.class b/Register.class new file mode 100644 index 0000000..d9d2ec3 Binary files /dev/null and b/Register.class differ diff --git a/Register.java b/Register.java new file mode 100644 index 0000000..2b1c50a --- /dev/null +++ b/Register.java @@ -0,0 +1,37 @@ +import javax.swing.*; +import java.awt.*; +import java.io.*; +import javax.swing.filechooser.FileNameExtensionFilter; + +public class Register{ + public static void sauvegarde(String name, int [][] g){ + int val[] = new int[9]; + + int actuVal=0; + int v=0; + + try{ + FileOutputStream fichier = new FileOutputStream(name); + DataOutputStream flux = new DataOutputStream(fichier); + + try{ + + + for(int i=0; i<9; i++){ + for(int j=0; j<9; j++){ + actuVal = g[i][j]; + v = (v*10) - actuVal; + } + flux.writeInt(-v); + v=0; + actuVal=0; + } + flux.close(); + }catch(IOException e){ + System.out.println("Lecture fichier imposible"); + } + }catch(FileNotFoundException e){ + System.out.println("Fichier non trouvé"); + } + } +} \ No newline at end of file diff --git a/SaisieGrille$1.class b/SaisieGrille$1.class index 73d31e9..5ad4860 100644 Binary files a/SaisieGrille$1.class and b/SaisieGrille$1.class differ diff --git a/SaisieGrille.class b/SaisieGrille.class index adb54b4..3a5691e 100644 Binary files a/SaisieGrille.class and b/SaisieGrille.class differ diff --git a/SudokuGenerator.class b/SudokuGenerator.class index 0511a21..682e770 100644 Binary files a/SudokuGenerator.class and b/SudokuGenerator.class differ