src/de/uapcore/sudoku/ActionHandler.java

changeset 2
5179eff8a9b6
child 3
ed931970b4ac
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/de/uapcore/sudoku/ActionHandler.java	Sat Jan 26 17:42:07 2013 +0100
@@ -0,0 +1,68 @@
+package de.uapcore.sudoku;
+
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import javax.swing.JOptionPane;
+
+/**
+ *
+ * @author mike
+ */
+public final class ActionHandler implements ActionListener {
+    
+    public static final String SAVE = "save";
+    public static final String CHECK = "check";
+    public static final String SOLVE = "solve";
+    
+    private Field field;
+    private Solver solver;
+    
+    public ActionHandler(Field f) {
+        field = f;
+        solver = new Solver();
+    }
+    
+    private void save() {
+        if (solver.check(field)) {
+            field.setAllCellsModified(false);
+            // TODO: save to file
+        } else {
+            JOptionPane.showMessageDialog(field,
+                    "Das Feld kann mit Fehlern nicht gespeichert werden!",
+                    "Sudoku", JOptionPane.ERROR_MESSAGE);
+        }
+    }
+    
+    private void check() {
+        if (solver.check(field)) {
+            JOptionPane.showMessageDialog(field, "Überprüfung erfolgreich!",
+                    "Sudoku", JOptionPane.INFORMATION_MESSAGE);
+        } else {
+            JOptionPane.showMessageDialog(field, "Das Feld enthält Fehler!",
+                    "Sudoku", JOptionPane.WARNING_MESSAGE);
+        }
+    }
+    
+    private void solve() {
+        // TODO: solve
+    }
+
+    @Override
+    public void actionPerformed(ActionEvent e) {
+        switch (e.getActionCommand()) {
+        case "save":
+            save();
+            break;
+        case "check":
+            check();
+            break;
+        case "solve":
+            solve();
+            break;
+        default:
+            throw new UnsupportedOperationException(
+                    "unknown action: "+e.getActionCommand());
+        }
+    }
+    
+}

mercurial