-
Notifications
You must be signed in to change notification settings - Fork 0
/
FrontFrame.java
281 lines (207 loc) · 6.04 KB
/
FrontFrame.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
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
273
274
275
276
277
278
279
280
281
import java.awt.*;
import java.awt.event.*;
import java.awt.font.*;
import javax.swing.*;
import java.util.*;
import java.io.*;
import java.util.Calendar;
import java.util.ArrayList;
import java.util.List;
import java.util.Arrays;
import java.util.Scanner;
class FrontFrame extends JFrame {
JTextField tt;
JLabel sel_Time;
JTextField hour_field;
JTextField min_field;
JComboBox<String>time_cycle_dropdown;
JLabel colon_Time;
JLabel period_Time;
JTextField period_hour;
JTextField period_min;
JLabel st_hour;
JLabel st_min;
JFileChooser fc;
private Button button_browse;
private Button start_sleep;
private Button start_shut;
int period_min_int=0;
int period_hour_int=0;
int hour_time=0;
int min_time=0;
String str_am_pm="AM";
ArrayList<String> Song_list=new ArrayList<String>();
int shut_sleep_flag=0;
FrontFrame(){
Font font=new Font(getTitle(), Font.BOLD,16);
tt = new JTextField();
tt.setBounds(20,30,280,20);
add(tt);
//tt.setFont(font2);
@SuppressWarnings("unsafe")
Button button_browse=new Button("Browse");
button_browse.setBounds(310, 30, 50, 20);
add(button_browse);
sel_Time=new JLabel("Select Time:");
sel_Time.setSize(sel_Time.getPreferredSize());
sel_Time.setLocation(20,60);
add(sel_Time);
//repaint();
hour_field=new JTextField();
hour_field.setBounds(100,60,25,20);
add(hour_field);
colon_Time=new JLabel(":");
colon_Time.setSize(colon_Time.getPreferredSize());
colon_Time.setLocation(126,60);
add(colon_Time);
min_field=new JTextField();
min_field.setBounds(131,60,25,20);
add(min_field);
String time_cycle[]={"AM","PM"};
JComboBox<String> time_cycle_dropdown=new JComboBox<String>(time_cycle);
time_cycle_dropdown.setBounds(160,60,45,20);
add(time_cycle_dropdown);
period_Time=new JLabel("Time Period to Play:");
period_Time.setSize(period_Time.getPreferredSize());
period_Time.setLocation(20,85);
add(period_Time);
period_hour=new JTextField();
period_hour.setBounds(135,85,25,20);
add(period_hour);
st_hour=new JLabel("Hour");
st_hour.setSize(st_hour.getPreferredSize());
st_hour.setLocation(163,85);
add(st_hour);
period_min=new JTextField();
period_min.setBounds(193,85,25,20);
add(period_min);
st_min=new JLabel("Min");
st_min.setSize(st_hour.getPreferredSize());
st_min.setLocation(220,85);
add(st_min);
Button start_sleep=new Button("Start & Sleep");
start_sleep.setBounds(20, 120, 80, 20);
add(start_sleep);
Button start_shut=new Button("Start & Shut Down");
start_shut.setBounds(260, 120, 110, 20);
add(start_shut);
HandlerClass handler=new HandlerClass();
button_browse.addActionListener(handler);
start_sleep.addActionListener(handler);
start_shut.addActionListener(handler);
time_cycle_dropdown.addItemListener(
new ItemListener(){
public void itemStateChanged(ItemEvent event){
if(event.getStateChange()==ItemEvent.SELECTED){
str_am_pm=(String)time_cycle_dropdown.getSelectedItem();
}
}
}
);
setTitle("Second_Dazz");
setSize(400,300);
setLocation(500,200);
setLayout(null);
setVisible(true);
setDefaultCloseOperation(EXIT_ON_CLOSE);
}
private class HandlerClass implements ActionListener{
public void actionPerformed(ActionEvent e){
//tt.setText("Test");
/*System.out.println(e.getActionCommand());*/
if(e.getActionCommand()=="Browse"){
class FileChooserDemo extends JFrame implements ActionListener{
FileChooserDemo(){
super("Select Songs");
Container c=getContentPane();
this.setVisible(true);
this.setSize(500,400);
fc=new JFileChooser();
fc.setMultiSelectionEnabled(true);
fc.addActionListener(this);
fc.setLayout(new FlowLayout());
c.add(fc);
}
public void actionPerformed(ActionEvent ae){
File[] f=fc.getSelectedFiles();
int leng=f.length;
String path[]=new String[leng];
String allfile="";
for(int i=0;i<leng;i++){
path[i]=f[i].getAbsolutePath();
path[i]=path[i].replace("\\","\\\\");
allfile=allfile+"-"+path[i];
Song_list.add(path[i]);
}
tt.setText(allfile);
//new Timer(path);
/*System.out.println(allfile);*/
this.setVisible(false);
}
}
new FileChooserDemo();
}
String str_period_hour=period_hour.getText();
String str_period_min=period_min.getText();
String str_hour_time=hour_field.getText();
String str_min_time=min_field.getText();
period_hour_int=changeInt(str_period_hour.trim());
period_min_int=changeInt(str_period_min.trim());
hour_time=changeInt(str_hour_time.trim());
min_time=changeInt(str_min_time.trim());
if(str_am_pm.equals("PM")){
hour_time+=12;
}
if(e.getActionCommand()=="Start & Shut Down"){
try{
shut_sleep_flag=1;
time_check();
}catch(NumberFormatException ne){
System.out.println("not a number");
}
}
if(e.getActionCommand()=="Start & Sleep"){
try{
shut_sleep_flag=2;
time_check();
}catch(NumberFormatException ne){
System.out.println("not a number");
}
}
}
}
public void time_check(){
while(true){
Calendar now=Calendar.getInstance();
int hour=now.get(Calendar.HOUR_OF_DAY);
int minute=now.get(Calendar.MINUTE);
if(hour==hour_time){
if(minute==min_time){
try{
new Music(Song_list,period_hour_int,period_min_int).PlayMusic(shut_sleep_flag);
break;
}catch(Exception ex){
ex.printStackTrace();
}
}
}
try{
Thread.sleep(10000);
}catch(Exception e){
e.printStackTrace();
}
}
}
public int changeInt(String str){
int i;
int n=0;
for(i=0;i<str.length();i++){
n*=10;
n+=str.charAt(i)-48;
}
return n;
}
public static void main(String[] args){
FrontFrame fc=new FrontFrame();
}
}