利用Runnable 接口实现多线程,编写一个Java小程序。在屏幕上显示时间,每隔一秒钟刷新一次。为使小程序不

利用Runnable 接口实现多线程,编写一个Java小程序。在屏幕上显示时间,每隔一秒钟刷新一次。为使小程序不影响其他程序的运行,使用了多线程。

第1个回答  推荐于2016-04-01
import javax.swing.JLabel;
import java.util.Date;
public class Time extends JFrame implements Runnable {
private JLabel timeLabel=null;
private Date d=null;
public static void main(String args[]) {
new Time():
}
public Time() {
this.setTitle("多线程");
this.setSize(400,300):
this.setVisible(true);
this.setDefaultOperationClose(JFrame.EXIT_ON_CLOSE);
timeLabel=new JLabel();
this.getContentPane.add(timeLabel,BorderLayout.NORTH);
Thread t=new Thread(this);
t.start();
}
public void run() {
while (true) {
d=new Date();
timeLabel.setText(d.toString());
}
}
}追问

嗯 加点注释吧

本回答被提问者采纳
相似回答