-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAsker.java
More file actions
272 lines (249 loc) · 8.89 KB
/
Asker.java
File metadata and controls
272 lines (249 loc) · 8.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
import javax.swing.*;
import java.awt.TextField;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
class AskSize implements ActionListener {
public AskSize(Creator _creator){
creator = _creator;
_this = this;
}
public void getDimenstions() {
frame = new JFrame("Maze");
frame.setLayout(null);
frame.getContentPane().setLayout(null);
frame.setBounds(100, 50, 360, 260);
frame.add(new JLabel("Size of field") { {
this.setBounds(30, 10, 120, 30);
this.setHorizontalAlignment(SwingConstants.CENTER);
}});
frame.add(new JButton("Small") { {
this.setBounds(30, 50, 120, 30);
this.addActionListener(_this);
}});
frame.add(new JButton("Average") { {
this.setBounds(30, 90, 120, 30);
this.addActionListener(_this);
}});
frame.add(new JButton("Big") { {
this.setBounds(30, 130, 120, 30);
this.addActionListener(_this);
}});
frame.add(new JButton("Huge") { {
this.setBounds(30, 170, 120, 30);
this.addActionListener(_this);
}});
frame.add(new JLabel("Height") { {
this.setBounds(200, 10, 120, 30);
this.setHorizontalAlignment(SwingConstants.CENTER);
}});
frame.add(new JLabel("Width") { {
this.setBounds(200, 90, 120, 30);
this.setHorizontalAlignment(SwingConstants.CENTER);
}});
frame.add(new JLabel("or") { {
this.setBounds(170, 10, 20, 30);
this.setHorizontalAlignment(SwingConstants.CENTER);
}});
heightField = new TextField("25");
heightField.setBounds(200, 50, 120, 30);
frame.add(heightField);
widthField = new TextField("14");
widthField.setBounds(200, 130, 120, 30);
frame.add(widthField);
frame.add(new JButton("Ok") { {
this.setBounds(200, 170, 120, 30);
this.addActionListener(_this);
}});
frame.setVisible(true);
try {
while (waitingForPush) {Thread.sleep(100);}
} catch (Exception ignored){}
}
@Override
public void actionPerformed(ActionEvent e) {
String text = ((JButton) e.getSource()).getText();
if (text.contains("Small")) {
creator.dimensions = new Pair<>(10, 15);
}
else if (text.contains("Average")) {
creator.dimensions = new Pair<>(20, 30);
}
else if (text.contains("Big")) {
creator.dimensions = new Pair<>(40, 60);
}
else if (text.contains("Huge")) {
creator.dimensions = new Pair<>(120, 180);
}
else if (text.contains("Ok")){
int height = 20, width = 30;
try {
height = Integer.parseInt(heightField.getText().replaceAll("\\D", ""));
} catch (Exception ignored) {}
try {
width = Integer.parseInt(widthField.getText().replaceAll("\\D", ""));
} catch (Exception ignored) {}
creator.dimensions = new Pair<>(height, width);
}
else {
return;
}
waitingForPush = false;
frame.dispose();
}
private boolean waitingForPush = true;
private AskSize _this; Creator creator; JFrame frame;
private TextField heightField, widthField;
}
class AskGenerate implements ActionListener {
public String getWay(){
JFrame frame = new JFrame("Maze");
frame.setLayout(null);
frame.setBounds(100, 50, 400, 265);
frame.add(new JLabel("How to generate") { {
this.setBounds(30, 10, 180, 30);
this.setHorizontalAlignment(SwingConstants.CENTER);
}});
frame.add(new JButton("Recursive Backtracker") { {
this.setBounds(30, 50, 180, 30);
this.addActionListener(_this);
}});
frame.add(new JLabel("combination of both =>") { {
this.setBounds(30, 90, 180, 30);
this.setHorizontalAlignment(SwingConstants.CENTER);
}});
frame.add(new JButton("Prim's algorithm") { {
this.setBounds(30, 130, 180, 30);
this.addActionListener(_this);
}});
frame.add(new JButton("Kruskal's algorithm") { {
this.setBounds(30, 170, 180, 30);
this.addActionListener(_this);
}});
frame.setVisible(true);
frame.add(new JButton("75:25") { {
this.setBounds(240, 50, 120, 30);
this.addActionListener(_this);
}});
frame.add(new JButton("50:50") { {
this.setBounds(240, 90, 120, 30);
this.addActionListener(_this);
}});
frame.add(new JButton("25:75") { {
this.setBounds(240, 130, 120, 30);
this.addActionListener(_this);
}});
try {
while (waitingForPush) Thread.sleep(100);
} catch (Exception ignored){}
frame.dispose();
return resultString;
}
@Override
public void actionPerformed(ActionEvent e) {
resultString = ((JButton)e.getSource()).getText();
waitingForPush = false;
}
private boolean waitingForPush = true;
private AskGenerate _this = this;
private String resultString;
}
class AskSolve implements ActionListener {
public String getWay(){
JFrame frame = new JFrame("Maze");
frame.setLayout(null);
frame.setBounds(100, 50, 225, 210);
frame.add(new JLabel("How to solve") { {
this.setBounds(30, 10, 160, 30);
this.setHorizontalAlignment(SwingConstants.CENTER);
}});
frame.add(new JButton("Depth First Search") { {
this.setBounds(30, 50, 160, 30);
this.addActionListener(_this);
}});
frame.add(new JButton("Breadth First Search") { {
this.setBounds(30, 90, 160, 30);
this.addActionListener(_this);
}});
frame.add(new JButton("Don't Solve") { {
this.setBounds(30, 130, 160, 30);
this.addActionListener(_this);
}});
frame.setVisible(true);
try {
while (waitingForPush) Thread.sleep(100);
} catch (Exception ignored){}
frame.dispose();
return resultString;
}
@Override
public void actionPerformed(ActionEvent e) {
resultString = ((JButton)e.getSource()).getText();
waitingForPush = false;
}
private boolean waitingForPush = true;
private AskSolve _this = this;
private String resultString;
}
class AskAnimate implements ActionListener {
public AskAnimate(MazePanel mp) {
JFrame frame = new JFrame();
frame.setLayout(null);
frame.setBounds(100, 50, 200, 295);
frame.add(new JLabel("Animation speed") { {
this.setBounds(30, 10, 130, 30);
this.setHorizontalAlignment(SwingConstants.CENTER);
}});
frame.add(new JButton("Fast") { {
this.setBounds(30, 50, 130, 30);
this.addActionListener(_this);
}});
frame.add(new JButton("Average") { {
this.setBounds(30, 90, 130, 30);
this.addActionListener(_this);
}});
frame.add(new JButton("Slow") { {
this.setBounds(30, 130, 130, 30);
this.addActionListener(_this);
}});
frame.add(new JButton("No animation") { {
this.setBounds(30, 170, 130, 30);
this.addActionListener(_this);
}});
ch = new JCheckBox("Skip generation");
ch.setBounds(30, 210, 130, 30);
frame.add(ch);
frame.setVisible(true);
try {
while(waitingForPush) Thread.sleep(100);
} catch (Exception ignored) {}
frame.dispose();
mp.animateGeneration = !animateGeneration;
mp.toAnimate = time != 0;
mp.animationTimeMs = time;
mp.sleepMS = mp.animationTimeMs / (mp.n * mp.m);
if (mp.sleepMS == 0) mp.sleepMS++;
}
@Override
public void actionPerformed(ActionEvent e) {
String text = ((JButton) e.getSource()).getText();
if (text.contains("Fast")) {
time = 10000;
}
else if (text.contains("Average")) {
time = 20000;
}
else if (text.contains("Slow")) {
time = 60000;
}
else {
time = 0;
}
animateGeneration = ch.isSelected();
waitingForPush = false;
}
private int time;
private boolean animateGeneration;
private AskAnimate _this = this;
private boolean waitingForPush = true;
private JCheckBox ch;
}