Sat, 26 Jan 2013 18:43:49 +0100
added NEW function
--- a/src/de/uapcore/sudoku/ActionHandler.java Sat Jan 26 18:38:12 2013 +0100 +++ b/src/de/uapcore/sudoku/ActionHandler.java Sat Jan 26 18:43:49 2013 +0100 @@ -80,10 +80,35 @@ private void solve() { // TODO: solve } + + private boolean saveUnsaved() { + boolean proceed = false; + if (field.isAnyCellModified()) { + int result = JOptionPane.showConfirmDialog(field, + "Das Feld ist ungespeichert - jetzt speichern?", + "Sudoku", JOptionPane.YES_NO_CANCEL_OPTION); + if (result == JOptionPane.YES_OPTION) { + if (save()) { + proceed = true; + } + } else if (result == JOptionPane.NO_OPTION) { + proceed = true; + } + } else { + proceed = true; + } + + return proceed; + } @Override public void actionPerformed(ActionEvent e) { switch (e.getActionCommand()) { + case NEW: + if (saveUnsaved()) { + field.clear(); + } + break; case SAVE: save(); break; @@ -94,18 +119,7 @@ solve(); break; case QUIT: - if (field.isAnyCellModified()) { - int result = JOptionPane.showConfirmDialog(field, - "Das Feld ist ungespeichert - jetzt speichern?", - "Sudoku", JOptionPane.YES_NO_CANCEL_OPTION); - if (result == JOptionPane.YES_OPTION) { - if (save()) { - System.exit(0); - } - } else if (result == JOptionPane.NO_OPTION) { - System.exit(0); - } - } else { + if (saveUnsaved()) { System.exit(0); } break;
--- a/src/de/uapcore/sudoku/Field.java Sat Jan 26 18:38:12 2013 +0100 +++ b/src/de/uapcore/sudoku/Field.java Sat Jan 26 18:43:49 2013 +0100 @@ -118,4 +118,12 @@ } return false; } + + public void clear() { + for (int x = 0 ; x < 9 ; x++) { + for (int y = 0 ; y < 9 ; y++) { + cells[x][y].setValue(0); + } + } + } }
--- a/src/de/uapcore/sudoku/SudokuTextField.java Sat Jan 26 18:38:12 2013 +0100 +++ b/src/de/uapcore/sudoku/SudokuTextField.java Sat Jan 26 18:43:49 2013 +0100 @@ -99,6 +99,10 @@ public void focusGained(FocusEvent e) { selectAll(); } + @Override + public void focusLost(FocusEvent e) { + select(0, 0); + } }); }