Skip to content

Commit 9153b82

Browse files
committed
Code Shrinking
1 parent 50f3cde commit 9153b82

File tree

1 file changed

+17
-14
lines changed

1 file changed

+17
-14
lines changed

src/com/company/guiController.java

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ class guiController extends JFrame implements Runnable{
1313

1414
sudokuInitializer sud = new sudokuInitializer(); //initializes array from file
1515
private int flag;
16+
private Runnable callSolver;
1617

1718
public void run() {
1819
flag = chooseInputStream(); //choose input method
@@ -90,14 +91,8 @@ private void guiInit() {
9091
if (flag != 0) {
9192
try {
9293
getText(); //takes in text from the GUI
94+
callSolver.run();
9395

94-
sud.printArray(); //debugging purpose
95-
solve.setEnabled(false);//cell value becomes fixed
96-
solver solver = new solver(Integer.parseInt(delay_input.getText()));
97-
Thread t2 = new Thread(solver);
98-
t2.start();
99-
System.out.println("Solving...");
100-
Clear.setEnabled(false);
10196

10297
} catch (Exception ex) {
10398
JOptionPane.showMessageDialog(null,"Invalid Input");//Throws error if the input is invalid
@@ -106,13 +101,7 @@ private void guiInit() {
106101
}
107102
}else {
108103
try {
109-
sud.printArray(); //debugging purpose
110-
solve.setEnabled(false);//cell value becomes fixed
111-
solver solver = new solver(Integer.parseInt(delay_input.getText()));
112-
Thread t2 = new Thread(solver);
113-
t2.start();
114-
System.out.println("Solving...");
115-
Clear.setEnabled(false);
104+
callSolver.run();
116105

117106
} catch (Exception ex) {
118107
JOptionPane.showMessageDialog(null,"Invalid Input");//Throws error if the input is invalid
@@ -141,7 +130,21 @@ private void guiInit() {
141130
setLocationRelativeTo(null);
142131
if (flag==0)
143132
Clear.setEnabled(false);
133+
134+
/*
135+
This lambda expression calls solver Class and passes the array
136+
*/
137+
callSolver = () -> {
138+
sud.printArray(); //debugging purpose
139+
solve.setEnabled(false);//cell value becomes fixed
140+
solver solver = new solver(Integer.parseInt(delay_input.getText()));
141+
Thread t2 = new Thread(solver);
142+
t2.start();
143+
System.out.println("Solving...");
144+
Clear.setEnabled(false);
145+
};
144146
}
147+
145148
/*
146149
\Function below clears the GUI
147150
sets the array to 0

0 commit comments

Comments
 (0)