-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMyWindow.java
More file actions
61 lines (53 loc) · 1.63 KB
/
MyWindow.java
File metadata and controls
61 lines (53 loc) · 1.63 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
import java.awt.*;
// import java.awt.event.*;
import java.util.Date;
import javax.swing.*;
public class MyWindow extends JFrame {
private JLabel headding;
private JLabel clockLabel;
private Font font=new Font("",Font.BOLD,35);
MyWindow(){
super.setTitle("My Clock");
super.setSize(500,500);
super.setLocation(300, 50);
this.createGUI();
this.startClock();
super.setVisible(true);
}
public void createGUI(){
headding= new JLabel("Nishant Clock");
clockLabel=new JLabel("clock");
headding.setFont(font);
clockLabel.setFont(font);
this.setLayout(new GridLayout(2,1));
this.add(headding);
this.add(clockLabel);
}
public void startClock(){
// without Threading
// Timer timer = new Timer(1000,new ActionListener(){
// @Override
// public void actionPerformed(ActionEvent e){
// // String DateTime=new Date().toString();
// String DateTime=new Date().toLocaleString();
// clockLabel.setText(DateTime);
// }
// });
// timer.start();
// Using Threading
Thread t= new Thread(){
public void run(){
try {
while(true){
String DateTime=new Date().toLocaleString();
clockLabel.setText(DateTime);
Thread.sleep(1000);
}
} catch (Exception e) {
e.printStackTrace();
}
}
};
t.start();
}
}