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.AttributeSet;
|
||||||
import javax.swing.text.BadLocationException;
|
import javax.swing.text.BadLocationException;
|
||||||
|
|
||||||
public class JTextFieldCharLimit extends PlainDocument{
|
public class JTextFieldCharLimit extends PlainDocument
|
||||||
private int limit;
|
{
|
||||||
|
private int max;
|
||||||
public JTextFieldCharLimit(int limit){
|
JTextFieldCharLimit(int max) {
|
||||||
this.limit = limit;
|
super();
|
||||||
}
|
this.max = max;
|
||||||
public void insertString(int offset, String str, AttributeSet set) throws BadLocationException{
|
}
|
||||||
if (str == null){
|
public void insertString(int offset, String text, AttributeSet attr) throws BadLocationException {
|
||||||
return;
|
if (text == null)
|
||||||
} else if ((getLength() + str.length() - getLength()) <= limit){
|
return;
|
||||||
super.insertString(offset, str, set);
|
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){
|
if(editable){
|
||||||
JTextField[][] case_editable = null;
|
JTextField[][] case_editable = null;
|
||||||
case_editable = new JTextField[9][9];
|
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 ligne = 0; ligne < 9; ligne++) {
|
||||||
for (int col = 0; col < 9; col++) {
|
for (int col = 0; col < 9; col++) {
|
||||||
if (grille[ligne][col] == 0){
|
if (grille[ligne][col] == 0){
|
||||||
case_editable[ligne][col] = new JTextField("", 1);
|
case_editable[ligne][col] = new JTextField("", 1);
|
||||||
|
case_editable[ligne][col].setDocument(new JTextFieldCharLimit(4));
|
||||||
}else{
|
}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].setFont(new Font("Arial", Font.PLAIN, 30));
|
||||||
case_editable[ligne][col].setHorizontalAlignment(JTextField.CENTER);
|
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 ligne = 0; ligne < 9; ligne++) {
|
||||||
for (int col = 0; col < 9; col++) {
|
for (int col = 0; col < 9; col++) {
|
||||||
if ((grid_values[ligne][col]) == 0) {
|
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] = 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].setFont(new Font("Arial", Font.PLAIN, 30));
|
||||||
case_modifiable[ligne][col].setHorizontalAlignment(JTextField.CENTER);
|
case_modifiable[ligne][col].setHorizontalAlignment(JTextField.CENTER);
|
||||||
if ((ligne % 3 == 0) && (ligne != 0) && (col % 3 == 0) && (col != 0)){
|
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