register
This commit is contained in:
parent
42c4ee8f89
commit
e1e3ebf602
Binary file not shown.
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
BIN
Grilles.class
Normal file
BIN
Grilles.class
Normal file
Binary file not shown.
58
Grilles.java
Normal file
58
Grilles.java
Normal file
@ -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;
|
||||
}
|
||||
}
|
BIN
Grilles/GrillesTest.gri
Normal file
BIN
Grilles/GrillesTest.gri
Normal file
Binary file not shown.
BIN
Main$2.class
Normal file
BIN
Main$2.class
Normal file
Binary file not shown.
BIN
Main$3.class
Normal file
BIN
Main$3.class
Normal file
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -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);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
BIN
Register.class
Normal file
BIN
Register.class
Normal file
Binary file not shown.
37
Register.java
Normal file
37
Register.java
Normal file
@ -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é");
|
||||
}
|
||||
}
|
||||
}
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading…
Reference in New Issue
Block a user