debut limit de caractere
This commit is contained in:
parent
8724af4581
commit
aa78e6e387
18
Sudoku/JTextFieldCharLimit.java
Normal file
18
Sudoku/JTextFieldCharLimit.java
Normal file
@ -0,0 +1,18 @@
|
||||
import javax.swing.text.PlainDocument;
|
||||
import javax.swing.text.AttributeSet;
|
||||
import javax.swing.text.BadLocationException;
|
||||
|
||||
public class JTextFieldCharLimit extends PlainDocument{
|
||||
private int limit;
|
||||
|
||||
public JTextFieldCharLimit(int limit){
|
||||
this.limit = limit;
|
||||
}
|
||||
public void insertString(int offset, String str, AttributeSet set) throws BadLocationException{
|
||||
if (str == null){
|
||||
return;
|
||||
} else if ((getLength() + str.length() - getLength()) <= limit){
|
||||
super.insertString(offset, str, set);
|
||||
}
|
||||
}
|
||||
}
|
@ -4,7 +4,11 @@ import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.io.*;
|
||||
import javax.swing.border.Border;
|
||||
import javax.swing.text.*;
|
||||
import javax.swing.text.PlainDocument;
|
||||
import javax.swing.text.AttributeSet;
|
||||
import javax.swing.text.BadLocationException;
|
||||
|
||||
|
||||
|
||||
public class grille extends JComponent{
|
||||
private static JLabel etat_exportation = new JLabel();
|
||||
@ -33,6 +37,13 @@ public class grille extends JComponent{
|
||||
if(editable){
|
||||
JTextField[][] case_editable = null;
|
||||
case_editable = new JTextField[9][9];
|
||||
for (int ligne = 0; ligne < 9; ligne++) {
|
||||
for (int col = 0; col < 9; col++) {
|
||||
case_editable[ligne][col] = new JTextField();
|
||||
case_editable[ligne][col].setDocument(new JTextFieldCharLimit(4));
|
||||
}
|
||||
}
|
||||
|
||||
for (int ligne = 0; ligne < 9; ligne++) {
|
||||
for (int col = 0; col < 9; col++) {
|
||||
if (grille[ligne][col] == 0){
|
||||
@ -61,10 +72,12 @@ public class grille extends JComponent{
|
||||
JLabel[][] case_depart = null;
|
||||
case_depart = new JLabel[9][9];
|
||||
case_modifiable = new JTextField[9][9];
|
||||
|
||||
|
||||
for (int ligne = 0; ligne < 9; ligne++) {
|
||||
for (int col = 0; col < 9; col++) {
|
||||
if ((grid_values[ligne][col]) == 0) {
|
||||
|
||||
case_modifiable[ligne][col].setDocument(new JTextFieldCharLimit(4));
|
||||
case_modifiable[ligne][col] = new JTextField("", 1);
|
||||
case_modifiable[ligne][col].setFont(new Font("Arial", Font.PLAIN, 30));
|
||||
case_modifiable[ligne][col].setHorizontalAlignment(JTextField.CENTER);
|
||||
|
Loading…
Reference in New Issue
Block a user