2024-04-30 13:51:32 +02:00
|
|
|
import javax.swing.*;
|
|
|
|
import java.awt.*;
|
|
|
|
import java.awt.event.*;
|
2024-05-01 19:03:45 +02:00
|
|
|
import java.io.*;
|
2024-04-30 13:51:32 +02:00
|
|
|
import java.io.File;
|
|
|
|
import java.io.PrintWriter;
|
|
|
|
import java.io.FileWriter;
|
|
|
|
import java.io.IOException;
|
|
|
|
import javax.swing.JFileChooser;
|
2024-05-01 19:03:45 +02:00
|
|
|
import javax.swing.filechooser.FileNameExtensionFilter;
|
2024-04-30 13:51:32 +02:00
|
|
|
|
|
|
|
public class MainCreation {
|
|
|
|
public static void main(String[] args) {
|
2024-05-01 19:03:45 +02:00
|
|
|
int [][] grille = new int [9][9];
|
|
|
|
//Création de la fenetre de selection + choix du dossier
|
2024-04-30 13:51:32 +02:00
|
|
|
JFrame selF = new JFrame("Choix de résolution du Sudoku");
|
|
|
|
selF.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
|
|
|
selF.setSize(400, 200);
|
|
|
|
selF.setLayout(new BorderLayout());
|
|
|
|
selF.setLocationRelativeTo(null);
|
|
|
|
JLabel sel = new JLabel("Quelle grilles souhaitez vous ?");
|
|
|
|
//Création des boutons
|
|
|
|
sel.setHorizontalAlignment(JLabel.CENTER);
|
|
|
|
JButton grilleVide = new JButton("Grille vide");
|
|
|
|
JButton grilleExiste = new JButton("Grille Existante");
|
|
|
|
|
|
|
|
JPanel boutonsSelect = new JPanel();
|
|
|
|
boutonsSelect.setLayout(new FlowLayout());
|
|
|
|
boutonsSelect.add(grilleVide);
|
|
|
|
boutonsSelect.add(grilleExiste);
|
|
|
|
|
|
|
|
selF.add(sel, BorderLayout.NORTH);
|
|
|
|
selF.add(boutonsSelect, BorderLayout.CENTER);
|
|
|
|
selF.setVisible(true);
|
|
|
|
//Action des bouton
|
|
|
|
grilleVide.addActionListener(new ActionListener() {
|
|
|
|
@Override
|
|
|
|
public void actionPerformed(ActionEvent e) {
|
|
|
|
selF.dispose();
|
2024-05-01 19:03:45 +02:00
|
|
|
Grilles.grilleVide(grille);
|
|
|
|
fenetreModification(grille);
|
2024-04-30 13:51:32 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
grilleExiste.addActionListener(new ActionListener() {
|
|
|
|
@Override
|
|
|
|
public void actionPerformed(ActionEvent e) {
|
|
|
|
selF.dispose();
|
2024-05-01 19:03:45 +02:00
|
|
|
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) {
|
2024-05-01 21:40:26 +02:00
|
|
|
Lecteur.lecture(fichier.getSelectedFile().getName(), grille);
|
|
|
|
fenetreModification(grille);
|
2024-05-01 19:03:45 +02:00
|
|
|
}
|
2024-04-30 13:51:32 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2024-05-01 19:03:45 +02:00
|
|
|
|
|
|
|
private static void fenetreModification(int[][] grille) {
|
2024-04-30 13:51:32 +02:00
|
|
|
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
|
|
|
|
JButton register = new JButton("Enregistrer");
|
|
|
|
register.addActionListener(new ActionListener() {
|
|
|
|
@Override
|
|
|
|
public void actionPerformed(ActionEvent e){
|
2024-05-01 19:03:45 +02:00
|
|
|
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);
|
2024-04-30 13:51:32 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
frame.add(register, BorderLayout.SOUTH); // Ajouter le bouton "Enregistrer"
|
|
|
|
|
|
|
|
frame.add(saisieGrille, BorderLayout.CENTER); // Ajouter la grille à la fenêtre
|
|
|
|
|
|
|
|
frame.pack();
|
|
|
|
frame.setLocationRelativeTo(null); // Centrer la fenêtre sur l'écran
|
|
|
|
frame.setVisible(true);
|
|
|
|
|
|
|
|
System.out.println("La fenêtre de création a été affichée.");
|
|
|
|
}
|
|
|
|
}
|