-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNewJFrame.java
More file actions
416 lines (365 loc) · 18.3 KB
/
Copy pathNewJFrame.java
File metadata and controls
416 lines (365 loc) · 18.3 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
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
package clock;
import java.awt.Color;
import java.util.Date;
import java.util.Calendar;
import java.util.GregorianCalendar;
import javax.swing.BorderFactory;
import javafx.embed.swing.JFXPanel;
import java.io.*;
import javafx.scene.media.Media;
import javafx.scene.media.MediaPlayer;
import javax.swing.JButton;
import javax.swing.GroupLayout.Alignment;
import javax.swing.LayoutStyle.ComponentPlacement;
import javax.swing.GroupLayout;
import java.awt.Font;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
public class NewJFrame extends javax.swing.JFrame {
private Timezone tz;
private Time t;
private Date date;
private Configure config;
private Color background,text,frame;
private JFontChooser f;
private AlarmClock a;
boolean sendAlarmSig = false;
final JFXPanel fxPanel = new JFXPanel();
MediaPlayer mediaplayer;
Media hit;
boolean alreadyPlaying = false;
boolean stopPressed = false;
int count = 0;
public NewJFrame() {
initComponents();
// Set day song
Timezone tempTz = new Timezone(time_zone);
Calendar tempCal = new GregorianCalendar(tempTz.getTimeZone());
String playFile = tempCal.get(Calendar.DAY_OF_WEEK) +".mp3" ;
System.out.println(playFile);
hit = new Media(new File(playFile).toURI().toString());
mediaplayer = new MediaPlayer(hit);
// End of block
new Thread()
{
public void run()
{
stopAlarm.setVisible(false);
while(true)
{
tz = new Timezone(time_zone); //get the selected time zone
Calendar cal = new GregorianCalendar(tz.getTimeZone()); //get details of that time zone
t = new Time(cal); //get current time
clock.setText(t.setTime(jRadioButton24,jRadioButton12)); //set time
date = new Date(); //get date
date_field.setText(" " + date);//set date
config = new Configure();
//Set alarm
if(sendAlarmSig) {
if(a.getStatus()) {
if(cal.get(Calendar.HOUR) == a.getHour() && cal.get(Calendar.MINUTE) == a.getMin() && cal.get(Calendar.SECOND) == a.getSec() && cal.get(Calendar.AM_PM) == (a.getAMPM()) ) {
// Play song
mediaplayer.play();
stopAlarm.setVisible(true);
}
}
}
}
}
}.start();
}
/**
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always
* regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {
jSlider1 = new javax.swing.JSlider();
jSlider2 = new javax.swing.JSlider();
jRadioButtonMenuItem1 = new javax.swing.JRadioButtonMenuItem();
jMenuItem1 = new javax.swing.JMenuItem();
jMenuItem2 = new javax.swing.JMenuItem();
buttonGroup1 = new javax.swing.ButtonGroup();
buttonGroup2 = new javax.swing.ButtonGroup();
jPanel1 = new javax.swing.JPanel();
clock = new javax.swing.JLabel();
date_field = new javax.swing.JLabel();
jButton2 = new javax.swing.JButton();
time_zone = new javax.swing.JComboBox<>();
jLabel1 = new javax.swing.JLabel();
stopAlarm = new javax.swing.JButton();
jButton1 = new javax.swing.JButton();
jMenuBar1 = new javax.swing.JMenuBar();
jMenu2 = new javax.swing.JMenu();
jMenu1 = new javax.swing.JMenu();
text_colour = new javax.swing.JMenuItem();
frame_colour = new javax.swing.JMenuItem();
bg_colour = new javax.swing.JMenuItem();
font_style = new javax.swing.JMenuItem();
jMenu3 = new javax.swing.JMenu();
jRadioButton12 = new javax.swing.JRadioButtonMenuItem();
jRadioButton24 = new javax.swing.JRadioButtonMenuItem();
jRadioButtonMenuItem1.setSelected(true);
jRadioButtonMenuItem1.setText("jRadioButtonMenuItem1");
jMenuItem1.setText("jMenuItem1");
jMenuItem2.setText("jMenuItem2");
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setBackground(new java.awt.Color(7, 6, 5));
jPanel1.setBackground(Color.BLACK);
clock.setFont(new java.awt.Font("DS-Digital", 0, 100)); // NOI18N
clock.setForeground(new java.awt.Color(0, 153, 255));
clock.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
clock.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(209, 131, 131), 4));
date_field.setFont(new java.awt.Font("DS-Digital", 1, 24)); // NOI18N
date_field.setForeground(new java.awt.Color(255, 245, 245));
jButton2.setFont(new Font("Sitka Text", Font.BOLD, 15)); // NOI18N
jButton2.setForeground(new java.awt.Color(31, 7, 7));
jButton2.setText("SET ALARM");
jButton2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton2ActionPerformed(evt);
}
});
time_zone.setFont(new java.awt.Font("Noto Sans CJK KR Medium", 3, 15)); // NOI18N
time_zone.setModel(new javax.swing.DefaultComboBoxModel<>(new String[] { "America/Los_Angeles", "Asia/Colombo", "Canada/Central", "Egypt", "Europe/Berlin", "Greenwich", "IST", "Japan" }));
time_zone.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
time_zoneActionPerformed(evt);
}
});
jLabel1.setFont(new java.awt.Font("Noto Sans CJK TC Medium", 1, 18)); // NOI18N
jLabel1.setForeground(new java.awt.Color(254, 242, 242));
jLabel1.setText("Select time zone");
stopAlarm.setFont(new Font("Sitka Text", Font.BOLD, 15)); // NOI18N
stopAlarm.setText("STOP THE ALARM");
stopAlarm.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
stopAlarmActionPerformed(evt);
}
});
JButton btnStopWatch = new JButton("STOP WATCH");
btnStopWatch.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
Stopwatch s = new Stopwatch();
s.setVisible(true);
}
});
btnStopWatch.setFont(new Font("Sitka Text", Font.BOLD, 15));
JButton btnNewButton = new JButton("TIMER");
btnNewButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
GUITimer t = new GUITimer();
t.setVisible(true);
}
});
btnNewButton.setFont(new Font("Sitka Text", Font.BOLD, 14));
javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
jPanel1Layout.setHorizontalGroup(
jPanel1Layout.createParallelGroup(Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addContainerGap(93, Short.MAX_VALUE)
.addGroup(jPanel1Layout.createParallelGroup(Alignment.TRAILING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addComponent(date_field, GroupLayout.PREFERRED_SIZE, 304, GroupLayout.PREFERRED_SIZE)
.addGap(359))
.addGroup(jPanel1Layout.createSequentialGroup()
.addGroup(jPanel1Layout.createParallelGroup(Alignment.TRAILING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addGap(45)
.addComponent(btnStopWatch)
.addPreferredGap(ComponentPlacement.RELATED, 276, Short.MAX_VALUE)
.addComponent(jButton2, GroupLayout.PREFERRED_SIZE, 143, GroupLayout.PREFERRED_SIZE)
.addGap(191)
.addComponent(btnNewButton, GroupLayout.PREFERRED_SIZE, 127, GroupLayout.PREFERRED_SIZE))
.addGroup(jPanel1Layout.createSequentialGroup()
.addComponent(jLabel1)
.addGap(113)
.addComponent(time_zone, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
.addGap(159))
.addGroup(jPanel1Layout.createSequentialGroup()
.addGap(93)
.addComponent(clock, GroupLayout.PREFERRED_SIZE, 822, GroupLayout.PREFERRED_SIZE)))
.addContainerGap(133, Short.MAX_VALUE))
.addGroup(jPanel1Layout.createSequentialGroup()
.addComponent(stopAlarm)
.addGap(440))))
);
jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addGap(29)
.addGroup(jPanel1Layout.createParallelGroup(Alignment.BASELINE)
.addComponent(jLabel1, GroupLayout.PREFERRED_SIZE, 28, GroupLayout.PREFERRED_SIZE)
.addComponent(time_zone, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
.addGap(65)
.addComponent(clock, GroupLayout.PREFERRED_SIZE, 134, GroupLayout.PREFERRED_SIZE)
.addPreferredGap(ComponentPlacement.UNRELATED)
.addComponent(date_field, GroupLayout.PREFERRED_SIZE, 26, GroupLayout.PREFERRED_SIZE)
.addGap(18)
.addGroup(jPanel1Layout.createParallelGroup(Alignment.LEADING)
.addComponent(btnStopWatch, GroupLayout.PREFERRED_SIZE, 29, GroupLayout.PREFERRED_SIZE)
.addGroup(jPanel1Layout.createParallelGroup(Alignment.BASELINE)
.addComponent(jButton2, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(btnNewButton, GroupLayout.DEFAULT_SIZE, 29, Short.MAX_VALUE)))
.addGap(26)
.addComponent(stopAlarm)
.addGap(96))
);
jPanel1.setLayout(jPanel1Layout);
jButton1.setText("jButton1");
jMenuBar1.setFont(new java.awt.Font("URW Bookman L", 1, 15)); // NOI18N
jMenuBar1.add(jMenu2);
jMenu1.setText("Digital Clock");
jMenu1.setFont(new java.awt.Font("Noto Sans CJK KR Medium", 1, 15)); // NOI18N
text_colour.setText("ClockText colour");
text_colour.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
text_colourActionPerformed(evt);
}
});
jMenu1.add(text_colour);
frame_colour.setText("Frame colour");
frame_colour.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
frame_colourActionPerformed(evt);
}
});
jMenu1.add(frame_colour);
bg_colour.setText("Background colour");
bg_colour.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
bg_colourActionPerformed(evt);
}
});
jMenu1.add(bg_colour);
font_style.setText("Font style");
font_style.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
font_styleActionPerformed(evt);
}
});
jMenu1.add(font_style);
jMenuBar1.add(jMenu1);
jMenu3.setText("Time Format");
jMenu3.setFont(new java.awt.Font("Noto Sans CJK TC Medium", 1, 15)); // NOI18N
buttonGroup1.add(jRadioButton12);
jRadioButton12.setText("12 hour");
jMenu3.add(jRadioButton12);
buttonGroup1.add(jRadioButton24);
jRadioButton24.setSelected(true);
jRadioButton24.setText("24 hour");
jMenu3.add(jRadioButton24);
jMenuBar1.add(jMenu3);
setJMenuBar(jMenuBar1);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
layout.setHorizontalGroup(
layout.createParallelGroup(Alignment.LEADING)
.addGroup(Alignment.TRAILING, layout.createSequentialGroup()
.addGap(29)
.addComponent(jPanel1, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(Alignment.LEADING)
.addGroup(Alignment.TRAILING, layout.createSequentialGroup()
.addContainerGap()
.addComponent(jPanel1, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
getContentPane().setLayout(layout);
pack();
}// </editor-fold>//GEN-END:initComponents
private void bg_colourActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bg_colourActionPerformed
background = config.get_background(bg_colour);
jPanel1.setBackground(background);
}//GEN-LAST:event_bg_colourActionPerformed
private void font_styleActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_font_styleActionPerformed
f = new JFontChooser(this,clock.getFont());
f.setVisible(true);
if(f.getReturnStatus() == JFontChooser.RET_OK){
clock.setFont(f.getFont());
}
f.dispose();
}//GEN-LAST:event_font_styleActionPerformed
private void text_colourActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_text_colourActionPerformed
text = config.get_text(text_colour);
clock.setForeground(text);
}//GEN-LAST:event_text_colourActionPerformed
private void frame_colourActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_frame_colourActionPerformed
frame = config.get_frame(frame_colour);
clock.setBorder(BorderFactory.createLineBorder(frame));
}//GEN-LAST:event_frame_colourActionPerformed
private void time_zoneActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_time_zoneActionPerformed
// TODO add your handling code here:
}//GEN-LAST:event_time_zoneActionPerformed
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
a = new AlarmClock();
a.setVisible(true);
sendAlarmSig = true;
}//GEN-LAST:event_jButton2ActionPerformed
private void stopAlarmActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_stopAlarmActionPerformed
// TODO add your handling code here:
mediaplayer.stop();
a = new AlarmClock();
stopAlarm.setVisible(false);
}//GEN-LAST:event_stopAlarmActionPerformed
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
/* Set the Nimbus look and feel */
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
/* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
* For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
*/
try {
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(NewJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(NewJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(NewJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(NewJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
//</editor-fold>
/* Create and display the form */
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new NewJFrame().setVisible(true);
}
});
}
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JMenuItem bg_colour;
private javax.swing.ButtonGroup buttonGroup1;
private javax.swing.ButtonGroup buttonGroup2;
private javax.swing.JLabel clock;
private javax.swing.JLabel date_field;
private javax.swing.JMenuItem font_style;
private javax.swing.JMenuItem frame_colour;
private javax.swing.JButton jButton1;
private javax.swing.JButton jButton2;
private javax.swing.JLabel jLabel1;
private javax.swing.JMenu jMenu1;
private javax.swing.JMenu jMenu2;
private javax.swing.JMenu jMenu3;
private javax.swing.JMenuBar jMenuBar1;
private javax.swing.JMenuItem jMenuItem1;
private javax.swing.JMenuItem jMenuItem2;
private javax.swing.JPanel jPanel1;
private javax.swing.JRadioButtonMenuItem jRadioButton12;
private javax.swing.JRadioButtonMenuItem jRadioButton24;
private javax.swing.JRadioButtonMenuItem jRadioButtonMenuItem1;
private javax.swing.JSlider jSlider1;
private javax.swing.JSlider jSlider2;
private javax.swing.JButton stopAlarm;
private javax.swing.JMenuItem text_colour;
private javax.swing.JComboBox<String> time_zone;
}