src/de/uapcore/sudoku/ActionHandler.java

Fri, 01 Feb 2013 10:18:47 +0100

author
Mike Becker <universe@uap-core.de>
date
Fri, 01 Feb 2013 10:18:47 +0100
changeset 8
e70a0e3555fb
parent 7
2c0a2766461c
permissions
-rw-r--r--

removed completeness test - the solver automatically returns false when the field is incomplete

3
ed931970b4ac added license and main menu
Mike Becker <universe@uap-core.de>
parents: 2
diff changeset
1 /*
ed931970b4ac added license and main menu
Mike Becker <universe@uap-core.de>
parents: 2
diff changeset
2 * Copyright 2013 Mike Becker. All rights reserved.
ed931970b4ac added license and main menu
Mike Becker <universe@uap-core.de>
parents: 2
diff changeset
3 *
ed931970b4ac added license and main menu
Mike Becker <universe@uap-core.de>
parents: 2
diff changeset
4 * Redistribution and use in source and binary forms, with or without
ed931970b4ac added license and main menu
Mike Becker <universe@uap-core.de>
parents: 2
diff changeset
5 * modification, are permitted provided that the following conditions are met:
ed931970b4ac added license and main menu
Mike Becker <universe@uap-core.de>
parents: 2
diff changeset
6 *
ed931970b4ac added license and main menu
Mike Becker <universe@uap-core.de>
parents: 2
diff changeset
7 * 1. Redistributions of source code must retain the above copyright
ed931970b4ac added license and main menu
Mike Becker <universe@uap-core.de>
parents: 2
diff changeset
8 * notice, this list of conditions and the following disclaimer.
ed931970b4ac added license and main menu
Mike Becker <universe@uap-core.de>
parents: 2
diff changeset
9 *
ed931970b4ac added license and main menu
Mike Becker <universe@uap-core.de>
parents: 2
diff changeset
10 * 2. Redistributions in binary form must reproduce the above copyright
ed931970b4ac added license and main menu
Mike Becker <universe@uap-core.de>
parents: 2
diff changeset
11 * notice, this list of conditions and the following disclaimer in the
ed931970b4ac added license and main menu
Mike Becker <universe@uap-core.de>
parents: 2
diff changeset
12 * documentation and/or other materials provided with the distribution.
ed931970b4ac added license and main menu
Mike Becker <universe@uap-core.de>
parents: 2
diff changeset
13 *
ed931970b4ac added license and main menu
Mike Becker <universe@uap-core.de>
parents: 2
diff changeset
14 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
ed931970b4ac added license and main menu
Mike Becker <universe@uap-core.de>
parents: 2
diff changeset
15 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
ed931970b4ac added license and main menu
Mike Becker <universe@uap-core.de>
parents: 2
diff changeset
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ed931970b4ac added license and main menu
Mike Becker <universe@uap-core.de>
parents: 2
diff changeset
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
ed931970b4ac added license and main menu
Mike Becker <universe@uap-core.de>
parents: 2
diff changeset
18 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
ed931970b4ac added license and main menu
Mike Becker <universe@uap-core.de>
parents: 2
diff changeset
19 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
ed931970b4ac added license and main menu
Mike Becker <universe@uap-core.de>
parents: 2
diff changeset
20 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
ed931970b4ac added license and main menu
Mike Becker <universe@uap-core.de>
parents: 2
diff changeset
21 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
ed931970b4ac added license and main menu
Mike Becker <universe@uap-core.de>
parents: 2
diff changeset
22 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ed931970b4ac added license and main menu
Mike Becker <universe@uap-core.de>
parents: 2
diff changeset
23 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
ed931970b4ac added license and main menu
Mike Becker <universe@uap-core.de>
parents: 2
diff changeset
24 * POSSIBILITY OF SUCH DAMAGE.
ed931970b4ac added license and main menu
Mike Becker <universe@uap-core.de>
parents: 2
diff changeset
25 */
ed931970b4ac added license and main menu
Mike Becker <universe@uap-core.de>
parents: 2
diff changeset
26
2
5179eff8a9b6 check functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
27 package de.uapcore.sudoku;
5179eff8a9b6 check functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
28
5179eff8a9b6 check functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
29 import java.awt.event.ActionEvent;
5179eff8a9b6 check functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
30 import java.awt.event.ActionListener;
6
5bab2e971333 file IO
Mike Becker <universe@uap-core.de>
parents: 5
diff changeset
31 import java.io.File;
5bab2e971333 file IO
Mike Becker <universe@uap-core.de>
parents: 5
diff changeset
32 import java.io.IOException;
5bab2e971333 file IO
Mike Becker <universe@uap-core.de>
parents: 5
diff changeset
33 import javax.swing.JFileChooser;
2
5179eff8a9b6 check functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
34 import javax.swing.JOptionPane;
5179eff8a9b6 check functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
35
5179eff8a9b6 check functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
36 /**
5179eff8a9b6 check functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
37 *
5179eff8a9b6 check functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
38 * @author mike
5179eff8a9b6 check functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
39 */
5179eff8a9b6 check functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
40 public final class ActionHandler implements ActionListener {
5179eff8a9b6 check functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
41
5179eff8a9b6 check functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
42 public static final String SAVE = "save";
5179eff8a9b6 check functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
43 public static final String CHECK = "check";
5179eff8a9b6 check functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
44 public static final String SOLVE = "solve";
5179eff8a9b6 check functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
45
3
ed931970b4ac added license and main menu
Mike Becker <universe@uap-core.de>
parents: 2
diff changeset
46 public static final String NEW = "new";
ed931970b4ac added license and main menu
Mike Becker <universe@uap-core.de>
parents: 2
diff changeset
47 public static final String OPEN = "open";
ed931970b4ac added license and main menu
Mike Becker <universe@uap-core.de>
parents: 2
diff changeset
48 public static final String SAVE_AS = "save as";
ed931970b4ac added license and main menu
Mike Becker <universe@uap-core.de>
parents: 2
diff changeset
49 public static final String QUIT = "quit";
ed931970b4ac added license and main menu
Mike Becker <universe@uap-core.de>
parents: 2
diff changeset
50 public static final String ABOUT = "about";
ed931970b4ac added license and main menu
Mike Becker <universe@uap-core.de>
parents: 2
diff changeset
51
2
5179eff8a9b6 check functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
52 private Field field;
5179eff8a9b6 check functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
53 private Solver solver;
5
8ddf4af937d7 moved field methods to field class + added (parts of the) document handler
Mike Becker <universe@uap-core.de>
parents: 4
diff changeset
54 private DocumentHandler doc;
2
5179eff8a9b6 check functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
55
5179eff8a9b6 check functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
56 public ActionHandler(Field f) {
5179eff8a9b6 check functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
57 field = f;
5179eff8a9b6 check functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
58 solver = new Solver();
5
8ddf4af937d7 moved field methods to field class + added (parts of the) document handler
Mike Becker <universe@uap-core.de>
parents: 4
diff changeset
59 doc = new DocumentHandler();
8ddf4af937d7 moved field methods to field class + added (parts of the) document handler
Mike Becker <universe@uap-core.de>
parents: 4
diff changeset
60 }
8ddf4af937d7 moved field methods to field class + added (parts of the) document handler
Mike Becker <universe@uap-core.de>
parents: 4
diff changeset
61
8ddf4af937d7 moved field methods to field class + added (parts of the) document handler
Mike Becker <universe@uap-core.de>
parents: 4
diff changeset
62 private boolean chooseSaveFilename() {
6
5bab2e971333 file IO
Mike Becker <universe@uap-core.de>
parents: 5
diff changeset
63 JFileChooser fc = new JFileChooser(".");
5bab2e971333 file IO
Mike Becker <universe@uap-core.de>
parents: 5
diff changeset
64 fc.setMultiSelectionEnabled(false);
5bab2e971333 file IO
Mike Becker <universe@uap-core.de>
parents: 5
diff changeset
65 if (fc.showSaveDialog(field) == JFileChooser.APPROVE_OPTION) {
5bab2e971333 file IO
Mike Becker <universe@uap-core.de>
parents: 5
diff changeset
66 File f = fc.getSelectedFile();
5bab2e971333 file IO
Mike Becker <universe@uap-core.de>
parents: 5
diff changeset
67 if (f.exists()) {
5bab2e971333 file IO
Mike Becker <universe@uap-core.de>
parents: 5
diff changeset
68 int result = JOptionPane.showConfirmDialog(field,
5bab2e971333 file IO
Mike Becker <universe@uap-core.de>
parents: 5
diff changeset
69 "Bereits existierende Datei überschreiben?", "Sudoku",
5bab2e971333 file IO
Mike Becker <universe@uap-core.de>
parents: 5
diff changeset
70 JOptionPane.YES_NO_OPTION);
5bab2e971333 file IO
Mike Becker <universe@uap-core.de>
parents: 5
diff changeset
71 if (result == JOptionPane.YES_OPTION) {
5bab2e971333 file IO
Mike Becker <universe@uap-core.de>
parents: 5
diff changeset
72 doc.setFilename(f.getAbsolutePath());
5bab2e971333 file IO
Mike Becker <universe@uap-core.de>
parents: 5
diff changeset
73 return true;
5bab2e971333 file IO
Mike Becker <universe@uap-core.de>
parents: 5
diff changeset
74 } else {
5bab2e971333 file IO
Mike Becker <universe@uap-core.de>
parents: 5
diff changeset
75 return false;
5bab2e971333 file IO
Mike Becker <universe@uap-core.de>
parents: 5
diff changeset
76 }
5bab2e971333 file IO
Mike Becker <universe@uap-core.de>
parents: 5
diff changeset
77 } else {
5bab2e971333 file IO
Mike Becker <universe@uap-core.de>
parents: 5
diff changeset
78 doc.setFilename(f.getAbsolutePath());
5bab2e971333 file IO
Mike Becker <universe@uap-core.de>
parents: 5
diff changeset
79 return true;
5bab2e971333 file IO
Mike Becker <universe@uap-core.de>
parents: 5
diff changeset
80 }
5bab2e971333 file IO
Mike Becker <universe@uap-core.de>
parents: 5
diff changeset
81 } else {
5bab2e971333 file IO
Mike Becker <universe@uap-core.de>
parents: 5
diff changeset
82 return false;
5bab2e971333 file IO
Mike Becker <universe@uap-core.de>
parents: 5
diff changeset
83 }
2
5179eff8a9b6 check functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
84 }
5179eff8a9b6 check functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
85
6
5bab2e971333 file IO
Mike Becker <universe@uap-core.de>
parents: 5
diff changeset
86 private void open() {
5bab2e971333 file IO
Mike Becker <universe@uap-core.de>
parents: 5
diff changeset
87 JFileChooser fc = new JFileChooser(".");
5bab2e971333 file IO
Mike Becker <universe@uap-core.de>
parents: 5
diff changeset
88 fc.setMultiSelectionEnabled(false);
5bab2e971333 file IO
Mike Becker <universe@uap-core.de>
parents: 5
diff changeset
89 if (fc.showOpenDialog(field) == JFileChooser.APPROVE_OPTION) {
5bab2e971333 file IO
Mike Becker <universe@uap-core.de>
parents: 5
diff changeset
90 File f = fc.getSelectedFile();
5bab2e971333 file IO
Mike Becker <universe@uap-core.de>
parents: 5
diff changeset
91 doc.setFilename(f.getAbsolutePath());
5bab2e971333 file IO
Mike Becker <universe@uap-core.de>
parents: 5
diff changeset
92 try {
5bab2e971333 file IO
Mike Becker <universe@uap-core.de>
parents: 5
diff changeset
93 doc.load(field);
5bab2e971333 file IO
Mike Becker <universe@uap-core.de>
parents: 5
diff changeset
94 } catch (IOException e) {
5bab2e971333 file IO
Mike Becker <universe@uap-core.de>
parents: 5
diff changeset
95 JOptionPane.showMessageDialog(field,
5bab2e971333 file IO
Mike Becker <universe@uap-core.de>
parents: 5
diff changeset
96 "Datei konnte nicht geladen werden: "+e.getMessage(),
5bab2e971333 file IO
Mike Becker <universe@uap-core.de>
parents: 5
diff changeset
97 "Sudoku", JOptionPane.ERROR_MESSAGE);
5bab2e971333 file IO
Mike Becker <universe@uap-core.de>
parents: 5
diff changeset
98 }
5bab2e971333 file IO
Mike Becker <universe@uap-core.de>
parents: 5
diff changeset
99 }
5bab2e971333 file IO
Mike Becker <universe@uap-core.de>
parents: 5
diff changeset
100 }
5bab2e971333 file IO
Mike Becker <universe@uap-core.de>
parents: 5
diff changeset
101
5bab2e971333 file IO
Mike Becker <universe@uap-core.de>
parents: 5
diff changeset
102 private boolean save(boolean rename) {
5bab2e971333 file IO
Mike Becker <universe@uap-core.de>
parents: 5
diff changeset
103 if (!doc.isFilenameSet() || rename) {
5
8ddf4af937d7 moved field methods to field class + added (parts of the) document handler
Mike Becker <universe@uap-core.de>
parents: 4
diff changeset
104 if (!chooseSaveFilename()) {
8ddf4af937d7 moved field methods to field class + added (parts of the) document handler
Mike Becker <universe@uap-core.de>
parents: 4
diff changeset
105 return false;
8ddf4af937d7 moved field methods to field class + added (parts of the) document handler
Mike Becker <universe@uap-core.de>
parents: 4
diff changeset
106 }
8ddf4af937d7 moved field methods to field class + added (parts of the) document handler
Mike Becker <universe@uap-core.de>
parents: 4
diff changeset
107 }
2
5179eff8a9b6 check functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
108 if (solver.check(field)) {
5179eff8a9b6 check functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
109 field.setAllCellsModified(false);
6
5bab2e971333 file IO
Mike Becker <universe@uap-core.de>
parents: 5
diff changeset
110 try {
5bab2e971333 file IO
Mike Becker <universe@uap-core.de>
parents: 5
diff changeset
111 doc.save(field);
5bab2e971333 file IO
Mike Becker <universe@uap-core.de>
parents: 5
diff changeset
112 } catch (IOException e) {
5bab2e971333 file IO
Mike Becker <universe@uap-core.de>
parents: 5
diff changeset
113 JOptionPane.showMessageDialog(field,
5bab2e971333 file IO
Mike Becker <universe@uap-core.de>
parents: 5
diff changeset
114 "Datei konnte nicht gespeichert werden: "+e.getMessage(),
5bab2e971333 file IO
Mike Becker <universe@uap-core.de>
parents: 5
diff changeset
115 "Sudoku", JOptionPane.ERROR_MESSAGE);
5bab2e971333 file IO
Mike Becker <universe@uap-core.de>
parents: 5
diff changeset
116 }
3
ed931970b4ac added license and main menu
Mike Becker <universe@uap-core.de>
parents: 2
diff changeset
117 return true;
2
5179eff8a9b6 check functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
118 } else {
5179eff8a9b6 check functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
119 JOptionPane.showMessageDialog(field,
5179eff8a9b6 check functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
120 "Das Feld kann mit Fehlern nicht gespeichert werden!",
5179eff8a9b6 check functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
121 "Sudoku", JOptionPane.ERROR_MESSAGE);
3
ed931970b4ac added license and main menu
Mike Becker <universe@uap-core.de>
parents: 2
diff changeset
122 return false;
2
5179eff8a9b6 check functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
123 }
5179eff8a9b6 check functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
124 }
5179eff8a9b6 check functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
125
5179eff8a9b6 check functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
126 private void check() {
5179eff8a9b6 check functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
127 if (solver.check(field)) {
5179eff8a9b6 check functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
128 JOptionPane.showMessageDialog(field, "Überprüfung erfolgreich!",
5179eff8a9b6 check functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
129 "Sudoku", JOptionPane.INFORMATION_MESSAGE);
5179eff8a9b6 check functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
130 } else {
5179eff8a9b6 check functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
131 JOptionPane.showMessageDialog(field, "Das Feld enthält Fehler!",
5179eff8a9b6 check functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
132 "Sudoku", JOptionPane.WARNING_MESSAGE);
5179eff8a9b6 check functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
133 }
5179eff8a9b6 check functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
134 }
5179eff8a9b6 check functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
135
5179eff8a9b6 check functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
136 private void solve() {
7
2c0a2766461c added solving algorithm
Mike Becker <universe@uap-core.de>
parents: 6
diff changeset
137 if (!solver.check(field) || !solver.solve(field)) {
2c0a2766461c added solving algorithm
Mike Becker <universe@uap-core.de>
parents: 6
diff changeset
138 JOptionPane.showMessageDialog(field, "Das Feld ist nicht lösbar!",
2c0a2766461c added solving algorithm
Mike Becker <universe@uap-core.de>
parents: 6
diff changeset
139 "Sudoku", JOptionPane.WARNING_MESSAGE);
2c0a2766461c added solving algorithm
Mike Becker <universe@uap-core.de>
parents: 6
diff changeset
140 }
2
5179eff8a9b6 check functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
141 }
4
b8588e318001 added NEW function
Mike Becker <universe@uap-core.de>
parents: 3
diff changeset
142
b8588e318001 added NEW function
Mike Becker <universe@uap-core.de>
parents: 3
diff changeset
143 private boolean saveUnsaved() {
b8588e318001 added NEW function
Mike Becker <universe@uap-core.de>
parents: 3
diff changeset
144 boolean proceed = false;
b8588e318001 added NEW function
Mike Becker <universe@uap-core.de>
parents: 3
diff changeset
145 if (field.isAnyCellModified()) {
b8588e318001 added NEW function
Mike Becker <universe@uap-core.de>
parents: 3
diff changeset
146 int result = JOptionPane.showConfirmDialog(field,
b8588e318001 added NEW function
Mike Becker <universe@uap-core.de>
parents: 3
diff changeset
147 "Das Feld ist ungespeichert - jetzt speichern?",
b8588e318001 added NEW function
Mike Becker <universe@uap-core.de>
parents: 3
diff changeset
148 "Sudoku", JOptionPane.YES_NO_CANCEL_OPTION);
b8588e318001 added NEW function
Mike Becker <universe@uap-core.de>
parents: 3
diff changeset
149 if (result == JOptionPane.YES_OPTION) {
6
5bab2e971333 file IO
Mike Becker <universe@uap-core.de>
parents: 5
diff changeset
150 if (save(false)) {
4
b8588e318001 added NEW function
Mike Becker <universe@uap-core.de>
parents: 3
diff changeset
151 proceed = true;
b8588e318001 added NEW function
Mike Becker <universe@uap-core.de>
parents: 3
diff changeset
152 }
b8588e318001 added NEW function
Mike Becker <universe@uap-core.de>
parents: 3
diff changeset
153 } else if (result == JOptionPane.NO_OPTION) {
b8588e318001 added NEW function
Mike Becker <universe@uap-core.de>
parents: 3
diff changeset
154 proceed = true;
b8588e318001 added NEW function
Mike Becker <universe@uap-core.de>
parents: 3
diff changeset
155 }
b8588e318001 added NEW function
Mike Becker <universe@uap-core.de>
parents: 3
diff changeset
156 } else {
b8588e318001 added NEW function
Mike Becker <universe@uap-core.de>
parents: 3
diff changeset
157 proceed = true;
b8588e318001 added NEW function
Mike Becker <universe@uap-core.de>
parents: 3
diff changeset
158 }
b8588e318001 added NEW function
Mike Becker <universe@uap-core.de>
parents: 3
diff changeset
159
b8588e318001 added NEW function
Mike Becker <universe@uap-core.de>
parents: 3
diff changeset
160 return proceed;
b8588e318001 added NEW function
Mike Becker <universe@uap-core.de>
parents: 3
diff changeset
161 }
2
5179eff8a9b6 check functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
162
5179eff8a9b6 check functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
163 @Override
5179eff8a9b6 check functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
164 public void actionPerformed(ActionEvent e) {
5179eff8a9b6 check functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
165 switch (e.getActionCommand()) {
4
b8588e318001 added NEW function
Mike Becker <universe@uap-core.de>
parents: 3
diff changeset
166 case NEW:
b8588e318001 added NEW function
Mike Becker <universe@uap-core.de>
parents: 3
diff changeset
167 if (saveUnsaved()) {
7
2c0a2766461c added solving algorithm
Mike Becker <universe@uap-core.de>
parents: 6
diff changeset
168 doc.clearFilename();
4
b8588e318001 added NEW function
Mike Becker <universe@uap-core.de>
parents: 3
diff changeset
169 field.clear();
b8588e318001 added NEW function
Mike Becker <universe@uap-core.de>
parents: 3
diff changeset
170 }
b8588e318001 added NEW function
Mike Becker <universe@uap-core.de>
parents: 3
diff changeset
171 break;
6
5bab2e971333 file IO
Mike Becker <universe@uap-core.de>
parents: 5
diff changeset
172 case OPEN:
5bab2e971333 file IO
Mike Becker <universe@uap-core.de>
parents: 5
diff changeset
173 open();
5bab2e971333 file IO
Mike Becker <universe@uap-core.de>
parents: 5
diff changeset
174 break;
3
ed931970b4ac added license and main menu
Mike Becker <universe@uap-core.de>
parents: 2
diff changeset
175 case SAVE:
6
5bab2e971333 file IO
Mike Becker <universe@uap-core.de>
parents: 5
diff changeset
176 save(false);
5bab2e971333 file IO
Mike Becker <universe@uap-core.de>
parents: 5
diff changeset
177 break;
5bab2e971333 file IO
Mike Becker <universe@uap-core.de>
parents: 5
diff changeset
178 case SAVE_AS:
5bab2e971333 file IO
Mike Becker <universe@uap-core.de>
parents: 5
diff changeset
179 save(true);
2
5179eff8a9b6 check functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
180 break;
3
ed931970b4ac added license and main menu
Mike Becker <universe@uap-core.de>
parents: 2
diff changeset
181 case CHECK:
2
5179eff8a9b6 check functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
182 check();
5179eff8a9b6 check functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
183 break;
3
ed931970b4ac added license and main menu
Mike Becker <universe@uap-core.de>
parents: 2
diff changeset
184 case SOLVE:
2
5179eff8a9b6 check functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
185 solve();
5179eff8a9b6 check functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
186 break;
3
ed931970b4ac added license and main menu
Mike Becker <universe@uap-core.de>
parents: 2
diff changeset
187 case QUIT:
4
b8588e318001 added NEW function
Mike Becker <universe@uap-core.de>
parents: 3
diff changeset
188 if (saveUnsaved()) {
3
ed931970b4ac added license and main menu
Mike Becker <universe@uap-core.de>
parents: 2
diff changeset
189 System.exit(0);
ed931970b4ac added license and main menu
Mike Becker <universe@uap-core.de>
parents: 2
diff changeset
190 }
ed931970b4ac added license and main menu
Mike Becker <universe@uap-core.de>
parents: 2
diff changeset
191 break;
ed931970b4ac added license and main menu
Mike Becker <universe@uap-core.de>
parents: 2
diff changeset
192 case ABOUT:
ed931970b4ac added license and main menu
Mike Becker <universe@uap-core.de>
parents: 2
diff changeset
193 JOptionPane.showMessageDialog(field,
ed931970b4ac added license and main menu
Mike Becker <universe@uap-core.de>
parents: 2
diff changeset
194 "Sudoku - Copyright (c) 2013 Mike Becker\nwww.uap-core.de"+
ed931970b4ac added license and main menu
Mike Becker <universe@uap-core.de>
parents: 2
diff changeset
195 "\nPublished under the BSD License",
ed931970b4ac added license and main menu
Mike Becker <universe@uap-core.de>
parents: 2
diff changeset
196 "Sudoku", JOptionPane.INFORMATION_MESSAGE);
ed931970b4ac added license and main menu
Mike Becker <universe@uap-core.de>
parents: 2
diff changeset
197 break;
2
5179eff8a9b6 check functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
198 default:
5179eff8a9b6 check functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
199 throw new UnsupportedOperationException(
5179eff8a9b6 check functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
200 "unknown action: "+e.getActionCommand());
5179eff8a9b6 check functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
201 }
5179eff8a9b6 check functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
202 }
5179eff8a9b6 check functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
203
5179eff8a9b6 check functions
Mike Becker <universe@uap-core.de>
parents:
diff changeset
204 }

mercurial