1.1 --- a/src/main/java/de/uapcore/sudoku/SudokuTextField.java Sat Jul 25 14:01:28 2020 +0200 1.2 +++ b/src/main/java/de/uapcore/sudoku/SudokuTextField.java Sat Jul 25 15:29:51 2020 +0200 1.3 @@ -34,8 +34,7 @@ 1.4 import java.awt.event.KeyEvent; 1.5 1.6 /** 1.7 - * 1.8 - * @author mike 1.9 + * A custom text field specifically for Sudoku number fields. 1.10 */ 1.11 public final class SudokuTextField extends JTextField { 1.12 1.13 @@ -105,15 +104,25 @@ 1.14 } 1.15 }); 1.16 } 1.17 - 1.18 + 1.19 + /** 1.20 + * Returns the current value in the field or zero if the field is empty. 1.21 + * 1.22 + * @return the number from 1 to 9 or zero if empty 1.23 + */ 1.24 public int getValue() { 1.25 - if (getText().length() > 0) { 1.26 + if (getText().isEmpty()) { 1.27 + return 0; 1.28 + } else { 1.29 return Integer.valueOf(getText()); 1.30 - } else { 1.31 - return 0; 1.32 } 1.33 } 1.34 - 1.35 + 1.36 + /** 1.37 + * Sets the field's value. 1.38 + * 1.39 + * @param v the number from 1 to 9 or zero to clear the field 1.40 + */ 1.41 public void setValue(int v) { 1.42 if (v == 0) { 1.43 setText(""); 1.44 @@ -124,12 +133,24 @@ 1.45 "Sudoku numbers must be in range 0-9 (0 means 'not set')"); 1.46 } 1.47 } 1.48 - 1.49 + 1.50 + /** 1.51 + * Sets the modified state of this field. 1.52 + * 1.53 + * Modified fields are displayed in blue color. 1.54 + * 1.55 + * @param modified a flag indicating whether this field is modified 1.56 + */ 1.57 public void setModified(boolean modified) { 1.58 this.modified = modified; 1.59 setForeground(modified?Color.BLUE:Color.BLACK); 1.60 } 1.61 - 1.62 + 1.63 + /** 1.64 + * Checks whether this field is in modified state. 1.65 + * 1.66 + * @return true if this field is modified 1.67 + */ 1.68 public boolean isModified() { 1.69 return modified; 1.70 }