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