-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtimer
More file actions
41 lines (41 loc) · 952 Bytes
/
timer
File metadata and controls
41 lines (41 loc) · 952 Bytes
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
package timer;
import java.awt.*;
import javax.swing.*;
public class RunnableTimerEx extends JFrame{
public RunnableTimerEx() {
setTitle("타이머");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setSize(1000,600);
Container c = getContentPane();
c.setLayout(new FlowLayout());
JLabel timerLabel = new JLabel();
timerLabel.setFont(new Font("Gothic",Font.ITALIC,80));
c.add(timerLabel);
TimerRunnable runnable = new TimerRunnable(timerLabel);
Thread th = new Thread(runnable);
setVisible(true);
th.start();
}
public static void main(String[] args) {
new RunnableTimerEx();
}
}
class TimerRunnable implements Runnable{
private JLabel timerLabel;
public TimerRunnable(JLabel timerLabel){
this.timerLabel=timerLabel;
}
public void run() {
int n=0;
while(true) {
timerLabel.setText(Integer.toString(n));
n++;
try {
Thread.sleep(1000);
}
catch(InterruptedException e){
return;
}
}
}
}