package untitled1;
import java.awt.BorderLayout;
import javax.swing.JFrame;
import javax.swing.JLabel;
import java.awt.*;
import javax.swing.*;
import java.util.Date;
import java.text.SimpleDateFormat;
public class Frame2 extends JFrame implements Runnable{
Thread a=new Thread();
public Frame2() {
try {
jbInit();
} catch (Exception exception) {
exception.printStackTrace();
}
}
private void jbInit() throws Exception {
getContentPane().setLayout(null);
jLabel1.setBorder(BorderFactory.createLineBorder(Color.black));
jLabel1.setText("");
jLabel1.setBounds(new Rectangle(19, 35, 221, 29));
this.getContentPane().add(jLabel1);
a.start();
}
public void run(){
while(true){
try {
Thread.sleep(1000);
} catch (InterruptedException ex) {
}
Date d = new Date();//得到系统当前时间
SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String timeB = sf.format(d);//得到指定格式的时间
jLabel1.setText(timeB);
}
}
JLabel jLabel1 = new JLabel();
}
请问我的jLabel1中为什么不能动态显示时间