You are on page 1of 2

DateTime.

java

1 package datetime;
2
3 import java.awt.EventQueue;
10
11 public class DateTime {
12
13 private JFrame frame;
14 private JLabel lblClock;
15
16 /**
17 * Launch the application.
18 */
19 public static void main(String[] args) {
20 EventQueue.invokeLater(new Runnable() {
21 public void run() {
22 try {
23 DateTime window = new DateTime();
24 window.frame.setVisible(true);
25 } catch (Exception e) {
26 e.printStackTrace();
27 }
28 }
29 });
30 }
31
32 public void datetime()
33 {
34 Thread datetime = new Thread()
35 {
36 public void run()
37 {
38 try
39 {
40 for(;;)
41 {
42 Calendar cal = new GregorianCalendar();
43 int day = cal.get(Calendar.DAY_OF_MONTH);
44 int month = cal.get(Calendar.MONTH);
45 int year = cal.get(Calendar.YEAR);
46
47 int second = cal.get(Calendar.SECOND);
48 int minute = cal.get(Calendar.MINUTE);
49 int hour = cal.get(Calendar.HOUR);
50
51 lblClock.setText("Time " + hour + ":" + minute + ":" + second
+ " " + "Date " + year + "/" + month + "/" + day);
52
53 sleep(1000);
54 }
55 }
56 catch(Exception e)
57 {
58
59 }
60 }
61 };
62 datetime.start();

Page 1
DateTime.java

63 }
64
65 /**
66 * Create the application.
67 */
68 public DateTime() {
69 initialize();
70 datetime();
71 }
72
73 /**
74 * Initialize the contents of the frame.
75 */
76 private void initialize() {
77 frame = new JFrame();
78 frame.setBounds(100, 100, 703, 365);
79 frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
80 frame.getContentPane().setLayout(null);
81
82 lblClock = new JLabel("Clock");
83 lblClock.setFont(new Font("Tahoma", Font.BOLD, 25));
84 lblClock.setBounds(24, 69, 640, 175);
85 frame.getContentPane().add(lblClock);
86 }
87
88 }
89

Page 2

You might also like