--- a/src/main/java/de/uapcore/sudoku/SudokuTextField.java Sat Jul 25 14:01:28 2020 +0200 +++ b/src/main/java/de/uapcore/sudoku/SudokuTextField.java Sat Jul 25 15:29:51 2020 +0200 @@ -34,8 +34,7 @@ import java.awt.event.KeyEvent; /** - * - * @author mike + * A custom text field specifically for Sudoku number fields. */ public final class SudokuTextField extends JTextField { @@ -105,15 +104,25 @@ } }); } - + + /** + * Returns the current value in the field or zero if the field is empty. + * + * @return the number from 1 to 9 or zero if empty + */ public int getValue() { - if (getText().length() > 0) { + if (getText().isEmpty()) { + return 0; + } else { return Integer.valueOf(getText()); - } else { - return 0; } } - + + /** + * Sets the field's value. + * + * @param v the number from 1 to 9 or zero to clear the field + */ public void setValue(int v) { if (v == 0) { setText(""); @@ -124,12 +133,24 @@ "Sudoku numbers must be in range 0-9 (0 means 'not set')"); } } - + + /** + * Sets the modified state of this field. + * + * Modified fields are displayed in blue color. + * + * @param modified a flag indicating whether this field is modified + */ public void setModified(boolean modified) { this.modified = modified; setForeground(modified?Color.BLUE:Color.BLACK); } - + + /** + * Checks whether this field is in modified state. + * + * @return true if this field is modified + */ public boolean isModified() { return modified; }