2024-05-01 15:05:23 +02:00
|
|
|
/*
|
|
|
|
|
|
2024-04-30 12:08:10 +02:00
|
|
|
import javax.swing.*;
|
|
|
|
|
import java.awt.event.*;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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) {
|
|
|
|
|
|
|
|
|
|
GrilleValide();
|
|
|
|
|
|
|
|
|
|
}
|
2024-05-01 15:05:23 +02:00
|
|
|
}
|
2024-04-30 12:08:10 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
public void GrilleValide() {
|
|
|
|
|
|
|
|
|
|
int comparateur;
|
|
|
|
|
int evaluant;
|
2024-04-30 17:31:44 +02:00
|
|
|
boolean valide = true;
|
|
|
|
|
int[] list_region;
|
2024-04-30 12:08:10 +02:00
|
|
|
|
|
|
|
|
for (int i = 0; i < this.GRID_SIZE; i++) {
|
|
|
|
|
for(int j = 0; j < this.GRID_SIZE; j++) {
|
|
|
|
|
|
2024-04-30 17:31:44 +02:00
|
|
|
if (!grid[i][j].getText().isEmpty()) {
|
2024-04-30 12:08:10 +02:00
|
|
|
|
|
|
|
|
evaluant = Integer.parseInt(grid[i][j].getText());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// test de validité sur les lignes
|
|
|
|
|
for (int x = i+1; x < this.GRID_SIZE; x++) {
|
|
|
|
|
|
|
|
|
|
if (grid[x][j].getText().isEmpty()) {
|
|
|
|
|
|
|
|
|
|
comparateur = 0;
|
|
|
|
|
}else{
|
|
|
|
|
|
|
|
|
|
comparateur = Integer.parseInt(grid[x][j].getText());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (evaluant == comparateur) {
|
|
|
|
|
|
|
|
|
|
System.out.println("grille invalide2");
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
for (int x = i-1; x >= 0; x--) {
|
|
|
|
|
|
|
|
|
|
if (grid[x][j].getText().isEmpty()) {
|
|
|
|
|
|
|
|
|
|
comparateur = 0;
|
|
|
|
|
}else{
|
|
|
|
|
|
|
|
|
|
comparateur = Integer.parseInt(grid[x][j].getText());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (evaluant == comparateur) {
|
|
|
|
|
|
|
|
|
|
System.out.println("grille invalide1");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//test de validité sur les colonnes
|
|
|
|
|
for (int x = j+1; x < this.GRID_SIZE; x++) {
|
|
|
|
|
|
|
|
|
|
if (grid[i][x].getText().isEmpty()) {
|
|
|
|
|
|
|
|
|
|
comparateur = 0;
|
|
|
|
|
}else{
|
|
|
|
|
|
|
|
|
|
comparateur = Integer.parseInt(grid[i][x].getText());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (evaluant == comparateur) {
|
|
|
|
|
|
|
|
|
|
System.out.println("grille invalide");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
for (int x = j-1; x >= 0; x--) {
|
|
|
|
|
|
|
|
|
|
if (grid[i][x].getText().isEmpty()) {
|
|
|
|
|
|
|
|
|
|
comparateur = 0;
|
|
|
|
|
}else{
|
|
|
|
|
|
|
|
|
|
comparateur = Integer.parseInt(grid[i][x].getText());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (evaluant == comparateur) {
|
|
|
|
|
|
|
|
|
|
System.out.println("grille invalide");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//test de validité sur la région
|
2024-04-30 17:31:44 +02:00
|
|
|
|
|
|
|
|
if ( i < 3) {
|
|
|
|
|
|
|
|
|
|
if ( j < 3) {
|
|
|
|
|
|
|
|
|
|
for (int v = 0; v < 3; v++) {
|
|
|
|
|
for (int w = 0; w < 3; w++) {
|
|
|
|
|
|
|
|
|
|
if (!grid[v][w].getText().isEmpty()) {
|
|
|
|
|
|
|
|
|
|
list_region.add(grid[v][w].getText().isEmpty());
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2024-04-30 12:08:10 +02:00
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-05-01 15:05:23 +02:00
|
|
|
}
|
2024-04-30 12:08:10 +02:00
|
|
|
|
2024-05-01 15:05:23 +02:00
|
|
|
*/
|