90 lines
3.4 KiB
Java
90 lines
3.4 KiB
Java
|
import javax.swing.*;
|
||
|
import java.awt.*;
|
||
|
import java.awt.event.*;
|
||
|
import java.io.File;
|
||
|
import java.io.PrintWriter;
|
||
|
import java.io.FileWriter;
|
||
|
import java.io.IOException;
|
||
|
import javax.swing.JFileChooser;
|
||
|
|
||
|
public class MainCreation {
|
||
|
public static void main(String[] args) {
|
||
|
//Création de la fenetre de selection
|
||
|
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();
|
||
|
int[][] grille = grilleVide();
|
||
|
fenetreModification(grille, false);
|
||
|
}
|
||
|
});
|
||
|
grilleExiste.addActionListener(new ActionListener() {
|
||
|
@Override
|
||
|
public void actionPerformed(ActionEvent e) {
|
||
|
selF.dispose();
|
||
|
int[][] grille = SudokuGenerator.readGridFromFile();
|
||
|
fenetreModification(grille, false);
|
||
|
}
|
||
|
});
|
||
|
}
|
||
|
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) {
|
||
|
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){
|
||
|
JFileChooser dialogue = new JFileChooser(new File("."));
|
||
|
if (dialogue.showOpenDialog(null)==JFileChooser.APPROVE_OPTION) {
|
||
|
dialogue.getSelectedFile();
|
||
|
}
|
||
|
}
|
||
|
});
|
||
|
|
||
|
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.");
|
||
|
}
|
||
|
}
|