import java.awt.FlowLayout;
import java.awt.event.*;
import javax.swing.*;
import java.util.*;
public class FrameTest {
public static void main(String[] args) {
JFrame f = new MyFrame();
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setVisible(true);
}
}
class MyFrame extends JFrame {
private JLabel label = new JLabel();
private Thread th;
public MyFrame() {
this.add(label);
th = new Thread() {
public void run() {
while(true) {
Date d = new Date();
String s = String.format("%tT", d);
label.setText(s);
try {
Thread.sleep(1000);
} catch(Exception e) {
}
}
}
};
th.start();
}
private void init() {
this.setSize(300, 200);
this.setLocation(300, 200);
this.setLayout(new FlowLayout());
}
}
Thread-dynamic-display-time.zip_Time_dynamic
版权申诉
49 浏览量
2022-09-24
04:13:20
上传
评论
收藏 600B ZIP 举报
林当时
- 粉丝: 100
- 资源: 1万+