src/de/uapcore/sudoku/ActionHandler.java

Sat, 26 Jan 2013 17:42:07 +0100

author
Mike Becker <universe@uap-core.de>
date
Sat, 26 Jan 2013 17:42:07 +0100
changeset 2
5179eff8a9b6
child 3
ed931970b4ac
permissions
-rw-r--r--

check functions

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