Merge branch 'master' of grond.iut-fbleau.fr:follea/SAE21_2024

This commit is contained in:
2024-05-04 18:37:52 +02:00
4 changed files with 0 additions and 284 deletions

View File

@@ -1,15 +0,0 @@
import javax.swing.*;
public class Main {
public static void main(String[] args) {
// affichage et création de la fenetre
SudokuGrid sudokuGrid = new SudokuGrid();
sudokuGrid.setSize(700,600);
sudokuGrid.setLocation(100, 100);
sudokuGrid.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
sudokuGrid.setVisible(true);
}
}

View File

@@ -1,83 +0,0 @@
import javax.swing.*;
import java.awt.*;
public class SudokuGrid extends JFrame {
private static final int GRID_SIZE = 9; // Taille de la grille Sudoku 9x9
private static final int REGION_SIZE = 3;
public static final boolean BOOL = true;
private JTextField[][] grid;
public SudokuGrid() {
// Panneau pour la grille Sudoku.
JPanel gridPanel = new JPanel();
gridPanel.setLayout(new GridLayout(GRID_SIZE, GRID_SIZE)); // Utiliser GridLayout
gridPanel.setBackground(new Color(88, 169, 191)); // Fond vert
// Initialiser la grille
grid = new JTextField[GRID_SIZE][GRID_SIZE];
for (int i = 0; i < GRID_SIZE; i++) {
for (int j = 0; j < GRID_SIZE; j++) {
grid[i][j] = new JTextField();
TextFilter filtre = new TextFilter(grid[i][j], GRID_SIZE, grid, i, j);
grid[i][j].addKeyListener(filtre);
grid[i][j].setHorizontalAlignment(JTextField.CENTER);
grid[i][j].setFont(new Font("Verdana", Font.BOLD,40));
gridPanel.add(grid[i][j]);
int top = 1;
int left = 1;
int bottom = 1;
int right = 1;
// Vérifier si la case est sur le bord de la région horizontalement
if ((j + 1) % REGION_SIZE == 0 && j != GRID_SIZE - 1) {
right = 5; // Ajouter une bordure plus épaisse à droite
}
// Vérifier si la case est sur le bord de la région verticalement
if ((i + 1) % REGION_SIZE == 0 && i != GRID_SIZE - 1) {
bottom = 5; // Ajouter une bordure plus épaisse en bas
}
// Appliquer la bordure à la case
grid[i][j].setBorder(BorderFactory.createMatteBorder(top, left, bottom, right, Color.BLACK));
}
}
// Panneau pour les boutons
JPanel bouton = new JPanel();
bouton.setBackground(new Color(88, 169, 191));
bouton.setPreferredSize(new Dimension(150, 0)); // Espace pour les boutons
// Bouton pour sauvegarder la grille
JButton save = new JButton("Sauvegarder");
SaveButton saver = new SaveButton(GRID_SIZE,grid);
save.addActionListener(saver);
// Bouton pour chargé la grille
JButton load = new JButton("Charger");
LoadButton loader = new LoadButton(GRID_SIZE, grid);
load.addActionListener(loader);
bouton.add(load);
bouton.add(save);
// Ajout des panneaux à la fenetre
getContentPane().add(gridPanel, BorderLayout.CENTER);
getContentPane().add(bouton, BorderLayout.EAST);
}
}

View File

@@ -1,83 +0,0 @@
import javax.swing.*;
import java.awt.*;
public class SudokuGridTesteur extends JFrame {
private static final int GRID_SIZE = 9; // Taille de la grille Sudoku 9x9
private static final int REGION_SIZE = 3;
public static final boolean BOOL = false;
private JTextField[][] grid;
public SudokuGridTesteur() {
// Panneau pour la grille Sudoku.
JPanel gridPanel = new JPanel();
gridPanel.setLayout(new GridLayout(GRID_SIZE, GRID_SIZE)); // Utiliser GridLayout
gridPanel.setBackground(new Color(88, 169, 191)); // Fond vert
// Initialiser la grille
grid = new JTextField[GRID_SIZE][GRID_SIZE];
for (int i = 0; i < GRID_SIZE; i++) {
for (int j = 0; j < GRID_SIZE; j++) {
grid[i][j] = new JTextField();
TextFilter filtre = new TextFilter(grid[i][j], GRID_SIZE, grid, i, j);
grid[i][j].addKeyListener(filtre);
grid[i][j].setHorizontalAlignment(JTextField.CENTER);
grid[i][j].setFont(new Font("Verdana", Font.BOLD,40));
gridPanel.add(grid[i][j]);
int top = 1;
int left = 1;
int bottom = 1;
int right = 1;
// Vérifier si la case est sur le bord de la région horizontalement
if ((j + 1) % REGION_SIZE == 0 && j != GRID_SIZE - 1) {
right = 5; // Ajouter une bordure plus épaisse à droite
}
// Vérifier si la case est sur le bord de la région verticalement
if ((i + 1) % REGION_SIZE == 0 && i != GRID_SIZE - 1) {
bottom = 5; // Ajouter une bordure plus épaisse en bas
}
// Appliquer la bordure à la case
grid[i][j].setBorder(BorderFactory.createMatteBorder(top, left, bottom, right, Color.BLACK));
}
}
// Panneau pour les boutons
JPanel bouton = new JPanel();
bouton.setBackground(new Color(88, 169, 191));
bouton.setPreferredSize(new Dimension(150, 0)); // Espace pour les boutons
// Bouton pour sauvegarder la grille
JButton save = new JButton("Sauvegarder");
SaveButton saver = new SaveButton(GRID_SIZE,grid);
save.addActionListener(saver);
// Bouton pour chargé la grille
JButton load = new JButton("Charger");
LoadButton loader = new LoadButton(GRID_SIZE, grid);
load.addActionListener(loader);
bouton.add(load);
bouton.add(save);
// Ajout des panneaux à la fenetre
getContentPane().add(gridPanel, BorderLayout.CENTER);
getContentPane().add(bouton, BorderLayout.EAST);
}
}

View File

@@ -1,103 +0,0 @@
import javax.swing.*;
import java.awt.event.*;
import java.awt.Color;
public class VerifButton implements ActionListener {
private int GRID_SIZE;
private JTextField[][] grid;
public VerifButton(int GRID_SIZE, JTextField[][] grid) {
this.GRID_SIZE = GRID_SIZE;
this.grid = grid;
}
@Override
public void actionPerformed(ActionEvent e) {
if (grilleValide()) {
JOptionPane.showMessageDialog(null, "La grille est valide.", "Validation", JOptionPane.INFORMATION_MESSAGE);
} else {
JOptionPane.showMessageDialog(null, "La grille n'est pas valide.", "Erreur", JOptionPane.ERROR_MESSAGE);
}
}
private boolean grilleValide() {
for (int row = 0; row < this.GRID_SIZE; row++) {
for (int col = 0; col < this.GRID_SIZE; col++) {
if (!grid[row][col].getText().isEmpty()) {
int evaluant = Integer.parseInt(grid[row][col].getText());
// Test de validité sur les lignes
for (int row2 = row + 1; row2 < this.GRID_SIZE; row2++) {
if (!grid[row2][col].getText().isEmpty()) {
int comparateur = Integer.parseInt(grid[row2][col].getText());
if (evaluant == comparateur) {
grid[row2][col].setBackground(Color.red);
grid[row][col].setBackground(Color.red);
return false;
}
}
}
for (int row2 = row - 1; row2 >= 0; row2--) {
if (!grid[row2][col].getText().isEmpty()) {
int comparateur = Integer.parseInt(grid[row2][col].getText());
if (evaluant == comparateur) {
grid[row2][col].setBackground(Color.red);
grid[row][col].setBackground(Color.red);
return false;
}
}
}
// Test de validité sur les colonnes
for (int col2 = col + 1; col2 < this.GRID_SIZE; col2++) {
if (!grid[row][col2].getText().isEmpty()) {
int comparateur = Integer.parseInt(grid[row][col2].getText());
if (evaluant == comparateur) {
grid[row][col2].setBackground(Color.red);
grid[row][col].setBackground(Color.red);
return false;
}
}
}
for (int col2 = col - 1; col2 >= 0; col2--) {
if (!grid[row][col2].getText().isEmpty()) {
int comparateur = Integer.parseInt(grid[row][col2].getText());
if (evaluant == comparateur) {
grid[row][col2].setBackground(Color.red);
grid[row][col].setBackground(Color.red);
return false;
}
}
}
// Vérifier la validité dans les régions
int rowregion = row/3*3;
int colregion = col/3*3;
for (int row2 = rowregion; row2 < rowregion + 3; row2++) {
for (int col2 = colregion; col2 < colregion + 3; col2++) {
if (row2 != row && col2 != col ) {
if (!grid[row2][col2].getText().isEmpty()) {
int comparateur = Integer.parseInt(grid[row2][col2].getText());
if (evaluant == comparateur) {
grid[row2][col2].setBackground(Color.red);
grid[row][col].setBackground(Color.red);
return false;
}
}
}
}
}
}
}
}
return true;
}
}