📄 time.java
字号:
package view.com.systime;
import java.awt.FlowLayout;
import java.text.SimpleDateFormat;
import java.util.Date;
import javax.swing.JFrame;
import javax.swing.JLabel;
/**
*
* @author linfeng
* 获得系统当前时间
*/
public class Time implements Runnable {
/**
* jl 标签
* sdf SimpleDateFormat类型
*/
private static JLabel jl;
private SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss");
public Time(JLabel jl) {
this.jl = jl;
Thread th = new Thread(this);
// th.setDaemon(true);
th.start();
// this.start();
}
public void run() {
while (true) {
this.jl.setText("系统时间:" + sdf.format(new Date()));
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
// TODO 自动生成 catch 块
e.printStackTrace();
}
}
}
// 测试
// public static void main(String[] args) {
// JFrame f = new JFrame();
// f.setSize(200, 200);
// JLabel lbl = new JLabel();
// f.setLayout(new FlowLayout());
// f.getContentPane().add(lbl);
// new Time(lbl);
// f.setVisible(true);
// }
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -