Sat, 26 Jan 2013 17:42:07 +0100
check functions
2 | 1 | package de.uapcore.sudoku; |
2 | ||
3 | import java.awt.event.ActionEvent; | |
4 | import java.awt.event.ActionListener; | |
5 | import javax.swing.JOptionPane; | |
6 | ||
7 | /** | |
8 | * | |
9 | * @author mike | |
10 | */ | |
11 | public final class ActionHandler implements ActionListener { | |
12 | ||
13 | public static final String SAVE = "save"; | |
14 | public static final String CHECK = "check"; | |
15 | public static final String SOLVE = "solve"; | |
16 | ||
17 | private Field field; | |
18 | private Solver solver; | |
19 | ||
20 | public ActionHandler(Field f) { | |
21 | field = f; | |
22 | solver = new Solver(); | |
23 | } | |
24 | ||
25 | private void save() { | |
26 | if (solver.check(field)) { | |
27 | field.setAllCellsModified(false); | |
28 | // TODO: save to file | |
29 | } else { | |
30 | JOptionPane.showMessageDialog(field, | |
31 | "Das Feld kann mit Fehlern nicht gespeichert werden!", | |
32 | "Sudoku", JOptionPane.ERROR_MESSAGE); | |
33 | } | |
34 | } | |
35 | ||
36 | private void check() { | |
37 | if (solver.check(field)) { | |
38 | JOptionPane.showMessageDialog(field, "Überprüfung erfolgreich!", | |
39 | "Sudoku", JOptionPane.INFORMATION_MESSAGE); | |
40 | } else { | |
41 | JOptionPane.showMessageDialog(field, "Das Feld enthält Fehler!", | |
42 | "Sudoku", JOptionPane.WARNING_MESSAGE); | |
43 | } | |
44 | } | |
45 | ||
46 | private void solve() { | |
47 | // TODO: solve | |
48 | } | |
49 | ||
50 | @Override | |
51 | public void actionPerformed(ActionEvent e) { | |
52 | switch (e.getActionCommand()) { | |
53 | case "save": | |
54 | save(); | |
55 | break; | |
56 | case "check": | |
57 | check(); | |
58 | break; | |
59 | case "solve": | |
60 | solve(); | |
61 | break; | |
62 | default: | |
63 | throw new UnsupportedOperationException( | |
64 | "unknown action: "+e.getActionCommand()); | |
65 | } | |
66 | } | |
67 | ||
68 | } |