-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapp.java
162 lines (120 loc) · 3.97 KB
/
app.java
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
/* Trabalho final: AED2 e PAED2 2010.2
*
* Labirinto
*
* Alunos: Elias Gabriel Amaral da Silva
* Flavio Fernando Vasconcelos
*/
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JSlider;
import java.awt.GridLayout;
import java.awt.Dimension;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import java.util.HashSet;
public class app extends JFrame {
int tela_w;
int tela_h;;
int casas_w = 8;
int casas_h = 6;
int borda = 12;
int min_tm = 3;
int max_tm = 600;
int def_tm = 150;
tela desenho;
JPanel scr;
private class size {
public int w, h;
public String str;
size(int w, int h, String str) {
this.w = w; this.h = h; this.str = str;
}
public String toString() { return str; }
}
private class size_listener implements ActionListener {
public void actionPerformed(ActionEvent e) {
JComboBox cb = (JComboBox)e.getSource();
size p = (size)cb.getSelectedItem();
reiniciar_size(p.w, p.h);
}
}
private class button_listener implements ActionListener {
public void actionPerformed(ActionEvent e) {
reiniciar_size(casas_w, casas_h);
}
}
private class slider_listener implements ChangeListener {
public void stateChanged(ChangeEvent e) {
var.sleep = max_tm - ((JSlider) e.getSource()).getValue() + min_tm;
}
}
private class thr implements Runnable {
tela t;
grafo<par<Integer, Integer>, par<HashSet<par<Integer, Integer>>, HashSet<Integer>>> g;
thr(tela t,
grafo<par<Integer, Integer>, par<HashSet<par<Integer, Integer>>, HashSet<Integer>>> g)
{ this.t = t; this.g = g; }
public void run() {
g.profundidade(t);
}
}
private void reiniciar_size(int w, int h) {
casas_w = w;
casas_h = h;
if (desenho != null)
scr.remove(desenho);
grafo<par<Integer, Integer>, par<HashSet<par<Integer, Integer>>, HashSet<Integer>>> g =
new grafo<par<Integer, Integer>,
par<HashSet<par<Integer, Integer>>, HashSet<Integer>>>(casas_w, casas_h);
g.kruskal();
desenho = new tela(borda, tela_w, tela_h, casas_w, casas_h,
g.linhas_horizontais(), g.linhas_verticais());
scr.add(desenho);
scr.validate();
new Thread(new thr(desenho, g)).start();
}
public app(int w, int h) {
tela_w = w;
tela_h = h;
scr = new JPanel();
JPanel q = new JPanel();
q.setLayout(new GridLayout(3, 1, 5, 10));
JComboBox j = new JComboBox();
j.addItem(new size(8, 6, "pequeno"));
j.addItem(new size(20, 15, "medio"));
j.addItem(new size(40, 30, "grande"));
j.addActionListener(new size_listener());
JButton b = new JButton("Reiniciar");
JSlider slider = new JSlider(min_tm, max_tm, max_tm - def_tm);
var.sleep = def_tm;
slider.addChangeListener(new slider_listener());
b.setMinimumSize(new Dimension(500, 500));
b.addActionListener(new button_listener());
q.add(slider);
q.add(j);
q.add(b);
scr.add(q);
reiniciar_size(casas_w, casas_h);
scr.add(desenho);
add(scr);
pack();
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLocationRelativeTo(null);
setTitle("Labirinto");
setResizable(false);
setVisible(true);
}
public static void main(String[] args) {
if (args.length >= 1 && args[0].equals("lap"))
new app(664, 504);
else if (args.length >= 1 && args[0].equals("mini"))
new app(224, 174);
else
new app(824, 624);
}
}