From b4b76148328e3af42ee9a0faf5cb1f45c76abdb1 Mon Sep 17 00:00:00 2001 From: keraudre Date: Sat, 4 May 2024 15:14:03 +0200 Subject: [PATCH] =?UTF-8?q?mise=20=C3=A0=20jour=20filtre=20de=20validation?= =?UTF-8?q?=20de=20la=20grille?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- TextFilter.java | 36 +++++++++++++++++++++++------------- 1 file changed, 23 insertions(+), 13 deletions(-) diff --git a/TextFilter.java b/TextFilter.java index 83f19ed..71e7d3c 100644 --- a/TextFilter.java +++ b/TextFilter.java @@ -1,6 +1,7 @@ import java.awt.event.*; import javax.swing.*; import java.awt.Color; +import java.util.ArrayList; public class TextFilter extends KeyAdapter { @@ -15,7 +16,7 @@ public class TextFilter extends KeyAdapter { private int col; - private JTextField Text2; + private ArrayList bad_numbers = new ArrayList(); public TextFilter (JTextField t,int GRID_SIZE, JTextField[][] grid, int i, int j) { @@ -64,15 +65,18 @@ public class TextFilter extends KeyAdapter { GrilleValide(chiffre); } - - if ( chiffre == KeyEvent.VK_BACK_SPACE) { - - if (!Text2.getText().isEmpty()) { - + if (!bad_numbers.isEmpty()) { + + if ( chiffre == KeyEvent.VK_BACK_SPACE) { Text.setBackground(Color.white); - Text2.setBackground(Color.white); - } + + while(!bad_numbers.isEmpty()) { + + grid[bad_numbers.removeFirst()][bad_numbers.removeFirst()].setBackground(Color.white); + + } + } } } @@ -90,7 +94,9 @@ public class TextFilter extends KeyAdapter { if (evaluant == comparateur) { this.grid[row2][col].setBackground(Color.red); this.grid[row][col].setBackground(Color.red); - this.Text2 = grid[row2][col]; + this.bad_numbers.add(row2); + this.bad_numbers.add(col); + } } } @@ -101,7 +107,8 @@ public class TextFilter extends KeyAdapter { if (evaluant == comparateur) { this.grid[row2][col].setBackground(Color.red); this.grid[row][col].setBackground(Color.red); - this.Text2 = grid[row2][col]; + this.bad_numbers.add(row2); + this.bad_numbers.add(col); } } } @@ -114,7 +121,8 @@ public class TextFilter extends KeyAdapter { if (evaluant == comparateur) { this.grid[row][col2].setBackground(Color.red); this.grid[row][col].setBackground(Color.red); - this.Text2 = grid[row][col]; + this.bad_numbers.add(row); + this.bad_numbers.add(col2); } } @@ -126,7 +134,8 @@ public class TextFilter extends KeyAdapter { if (evaluant == comparateur) { this.grid[row][col2].setBackground(Color.red); this.grid[row][col].setBackground(Color.red); - this.Text2 = grid[row][col2]; + this.bad_numbers.add(row); + this.bad_numbers.add(col2); } } } @@ -146,7 +155,8 @@ public class TextFilter extends KeyAdapter { if (evaluant == comparateur) { this.grid[row2][col2].setBackground(Color.red); this.grid[row][col].setBackground(Color.red); - this.Text2 = grid[row2][col2]; + this.bad_numbers.add(row2); + this.bad_numbers.add(col2); } } }