-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcountdown.java
More file actions
34 lines (27 loc) · 847 Bytes
/
countdown.java
File metadata and controls
34 lines (27 loc) · 847 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
package 軟體工程;
import javax.swing.*;
import java.awt.*;
import java.util.Timer;
import java.util.TimerTask;
public class countdown {
public static void main(String[] args) {
JFrame jframe = new JFrame();
JLabel jLabel = new JLabel();
jframe.setLayout(new FlowLayout());
jframe.setBounds(500, 300, 400, 100);
jframe.add(jLabel);
jframe.setVisible(true);
Timer timer = new Timer();
timer.scheduleAtFixedRate(new TimerTask() {
int x = 60;
public void run() {
jLabel.setText("Time left: " + x);
x--;
if (x < 0) {
timer.cancel();
jLabel.setText("Time Over");
}
}
}, 0, 1000);
}
}