-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathClocktype.java
119 lines (99 loc) · 2.71 KB
/
Clocktype.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
import java.util.*;
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
import java.sql.*;
public class Clocktype{
public JLabel jb;
public int sec=59;
public int min=9;
JFrame jf;
public Clocktype(JFrame jf1)
{
jf = jf1;
jb = new JLabel(min+":"+sec);
Seconds R1 = new Seconds( );
R1.start();
Minutes R2 = new Minutes();
R2.start();
}
public String zero(int num)
{
String number=( num < 10) ? ("0"+num) : (""+num);
return number; //Add leading zero if needed
}
class Seconds implements Runnable
{
private Thread t;
private String threadName;
Seconds( )
{
threadName = "Second";
}
public void run()
{
try {
while(true)
{
for(int i = 59; i>=0; i--)
{
sec=i;
jb.setFont(new Font("Arial",21,24));
jb.setForeground(Color.blue);
jb.setText(zero(min)+":"+zero(sec));
if(min ==0 && sec==0)
{
jf.setEnabled(false);
jf.setVisible(false);
return;
}
Thread.sleep(1000);
}
}
}
catch (InterruptedException e)
{
System.out.println("Thread " + threadName + " interrupted.");
}
}
public void start ()
{
if (t == null)
{
t = new Thread (this, threadName);
t.start ();
}
}
}
class Minutes implements Runnable {
private Thread t;
private String threadName;
Minutes( )
{threadName = "Minute";}
public void run()
{
try {
while(true)
{
for(int i =9; i>=0; i--)
{
min=i;
Thread.sleep(60000);
}
}
}
catch (InterruptedException e)
{
System.out.println("Thread " + threadName + " interrupted.");
}
}
public void start ()
{
if (t == null)
{
t = new Thread (this, threadName);
t.start ();
}
}
}
}