-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDigitalClock.java
More file actions
82 lines (73 loc) · 2.44 KB
/
DigitalClock.java
File metadata and controls
82 lines (73 loc) · 2.44 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
import java.awt.Color;
import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.Label;
import java.util.Calendar;
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author tarun
*/
public class DigitalClock extends javax.swing.JPanel implements Runnable{
/**
* Creates new form DigitalClock
*/
Label l;
Thread th;
Calendar cal;
public DigitalClock() {
setLayout(new FlowLayout(FlowLayout.CENTER));
l = new Label(" ");
add(l);
setBackground(Color.white);
setSize(200,400);
setVisible(true);
th = new Thread(this);
th.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() {
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
this.setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 619, Short.MAX_VALUE)
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 41, Short.MAX_VALUE)
);
}// </editor-fold>//GEN-END:initComponents
@Override
public void run() {
while(true){
try {
cal = Calendar.getInstance();
int hours,min,sec;
hours = cal.get(Calendar.HOUR_OF_DAY);
min = cal.get(Calendar.MINUTE);
sec = cal.get(Calendar.SECOND);
Font f = new Font("Serif", 1, 18);
l.setFont(f);
l.setBackground(Color.WHITE);
l.setText("Time - " + hours + ":" + min + ":" + sec);
Thread.sleep(1000);
}
catch (InterruptedException ex) {
System.out.println(ex);
}
}
}
// Variables declaration - do not modify//GEN-BEGIN:variables
// End of variables declaration//GEN-END:variables
}