added built-in check to the Cell data class to ensure initial values cannot be overridden by the user (even accidentally).

This commit is contained in:
Josh Ashton
2024-03-22 11:26:36 -06:00
parent 3744218040
commit 5e3c4151a6
+10 -7
View File
@@ -99,8 +99,7 @@ public class Board extends JPanel {
private Cell cell; private Cell cell;
private JLabel valueLabel; private JLabel valueLabel;
private Note[] notesLabels = new Note[9]; private Note[] notesLabels = new Note[9];
private boolean notes; // true for notes, false for value private boolean noteMode; // true to display notes, or display value
private boolean cellGUIStartMode;
/** /**
* Create a new CellGUI object with the given single cell. * Create a new CellGUI object with the given single cell.
@@ -110,16 +109,16 @@ public class Board extends JPanel {
* @param cell * @param cell
* @param startInNotesOrValueMode * @param startInNotesOrValueMode
*/ */
public CellGUI(Cell cell, boolean notes, Theme theme) { public CellGUI(Cell cell, boolean noteMode, Theme theme) {
super(); super();
this.cell = cell; this.cell = cell;
this.notes = notes; this.noteMode = noteMode;
this.theme = theme; this.theme = theme;
style(); style();
// Populate the cell with the appropriate value or notes. // Populate the cell with the appropriate value or notes.
if(cell.getValue() == 0) { if(cell.getValue() == 0) {
notes = !notes; noteMode = !noteMode; // Flip for use with setNoteMode()
valueLabel = new JLabel(""); valueLabel = new JLabel("");
setNoteMode(); setNoteMode();
} else { } else {
@@ -186,10 +185,12 @@ public class Board extends JPanel {
/** /**
* Toggle the mode of the cell between value and note, including the * Toggle the mode of the cell between value and note, including the
* layout of the cell. * layout of the cell.
*
* If the current mode is value, switch to note mode, and vice versa.
*/ */
public void setNoteMode() { public void setNoteMode() {
removeAll(); removeAll();
if(notes) { if(noteMode) {
setLayout(valueLayout); setLayout(valueLayout);
add(valueLabel); add(valueLabel);
@@ -199,11 +200,13 @@ public class Board extends JPanel {
generateNotes(); generateNotes();
for(int i = 0; i < 9; i++) for(int i = 0; i < 9; i++)
add(notesLabels[i]); add(notesLabels[i]);
System.out.println("Displaying notes.");
} }
repaint(); repaint();
revalidate(); revalidate();
notes = !notes; noteMode = !noteMode;
} }
/** /**