-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.java
144 lines (120 loc) · 3.07 KB
/
main.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
import javax.swing.*;
import java.awt.FlowLayout;
import java.awt.GridLayout;
import java.awt.Color;
import java.awt.event.*;
import javax.swing.event.*;
import pkg.*;
public class main extends JFrame{
JPanel control;
JPanel buttons;
JPanel sliders;
JLabel zoomlabel;
JLabel speedlabel;
JButton run;
JButton snode;
JButton enode;
JButton reset;
static int rerun = 0;
main(int w,int h){
this.setSize(w,h);
display dis = new display(w,h-60);
dis.setBounds(0,60,w,h-60);
dis.setLayout(null);
dis.setVisible(true);
// buttons
snode = new JButton("SNode");
snode.setBounds(0,10,80,40);
snode.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
dis.colorvalue = 2;
}
});
enode = new JButton("ENode");
enode.setBounds(80,10,80,40);
enode.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
dis.colorvalue = 3;
}
});
run = new JButton("Run");
run.setBounds(160,10,80,40);
run.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
if(rerun ==0){
if(dis.start()==0){
rerun = 1;
((JButton)e.getSource()).setText("Clean");
}
}else{
dis.clean();
rerun = 0;
((JButton)e.getSource()).setText("Run");
}
}
});
reset = new JButton("Reset");
reset.setBounds(240,10,80,40);
reset.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
dis.reset();
run.setText("Run");
}
});
//button end heres
//zoom slider
JSlider zoom = new JSlider(JSlider.HORIZONTAL,10,50,20);
zoom.addChangeListener(new ChangeListener(){
public void stateChanged(ChangeEvent e){
int val = ((JSlider)e.getSource()).getValue();
// System.out.println(val);
dis.setboxno(val);
}
});
JSlider speed = new JSlider(JSlider.HORIZONTAL,0,20,20);
speed.addChangeListener(new ChangeListener(){
public void stateChanged(ChangeEvent e){
int val = ((JSlider)e.getSource()).getValue();
// System.out.println(20-val);
dis.setspeed(20-val);
}
});
//end
zoom.setBounds(50,0,160,30);
speed.setBounds(50,30,160,30);
zoomlabel = new JLabel("Zoom");
speedlabel = new JLabel("Speed");
zoomlabel.setBounds(0,0,50,30);
speedlabel.setBounds(0,30,50,30);
control = new JPanel();
buttons = new JPanel();
sliders = new JPanel();
control.setBounds(5,0,w,60);
control.setLayout(null);
control.setVisible(true);
buttons.setBounds(0,0,(int)(w*0.6),60);
buttons.setLayout(null);
buttons.setVisible(true);
sliders.setBounds((int)(w*0.6),0,w,60);
sliders.setLayout(null);
sliders.setVisible(true);
buttons.add(enode);
buttons.add(snode);
buttons.add(run);
buttons.add(reset);
sliders.add(zoomlabel);
sliders.add(speedlabel);
sliders.add(zoom);
sliders.add(speed);
control.add(buttons);
control.add(sliders);
this.add(dis);
this.add(control);
}
public static void main(String[] args) {
main a = new main(600,660);
a.setLayout(null);
a.setVisible(true);
a.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}