fin limite de charactere
This commit is contained in:
Binary file not shown.
@@ -2,17 +2,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);
|
||||
}
|
||||
}
|
||||
public class JTextFieldCharLimit extends PlainDocument
|
||||
{
|
||||
private int max;
|
||||
JTextFieldCharLimit(int max) {
|
||||
super();
|
||||
this.max = max;
|
||||
}
|
||||
public void insertString(int offset, String text, AttributeSet attr) throws BadLocationException {
|
||||
if (text == null)
|
||||
return;
|
||||
if ((getLength() + text.length()) <= max) {
|
||||
super.insertString(offset, text, attr);
|
||||
}
|
||||
}
|
||||
}
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
+5
-9
@@ -37,19 +37,16 @@ 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){
|
||||
case_editable[ligne][col] = new JTextField("", 1);
|
||||
case_editable[ligne][col].setDocument(new JTextFieldCharLimit(4));
|
||||
}else{
|
||||
case_editable[ligne][col] = new JTextField(String.valueOf(grille[ligne][col]), 1);
|
||||
case_editable[ligne][col] = new JTextField(1);
|
||||
case_editable[ligne][col].setDocument(new JTextFieldCharLimit(4));
|
||||
case_editable[ligne][col].setText(String.valueOf(grille[ligne][col]));
|
||||
}
|
||||
case_editable[ligne][col].setFont(new Font("Arial", Font.PLAIN, 30));
|
||||
case_editable[ligne][col].setHorizontalAlignment(JTextField.CENTER);
|
||||
@@ -76,9 +73,8 @@ public class grille extends JComponent{
|
||||
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].setDocument(new JTextFieldCharLimit(4));
|
||||
case_modifiable[ligne][col].setFont(new Font("Arial", Font.PLAIN, 30));
|
||||
case_modifiable[ligne][col].setHorizontalAlignment(JTextField.CENTER);
|
||||
if ((ligne % 3 == 0) && (ligne != 0) && (col % 3 == 0) && (col != 0)){
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Reference in New Issue
Block a user