为什么线程无法刷新?
import java.io.*;
import java.awt.*;
import javax.swing.*;
import java.lang.*;
import java.util.*;
public class currentTime extends JDialog implements Runnable
{
private Calendar rightnow,old;
private JTextArea ta;
private String str;
public currentTime(String title)
{
setTitle(title);
rightnow=Calendar.getInstance();
Init();
}
public void Init()
{
str=""+rightnow.get(Calendar.YEAR);
str+="年"+(rightnow.get(Calendar.MONTH)+1);
str+="月"+rightnow.get(Calendar.DATE)+"日";
str+=" "+rightnow.get(Calendar.HOUR_OF_DAY)+":";
str+=rightnow.get(Calendar.MINUTE)+":";
str+=rightnow.get(Calendar.SECOND);
ta=new JTextArea();
ta.setBackground(Color.GRAY);
ta.setText(str);
ta.setEditable(false);
add(ta);
pack();validate();setVisible(true);
}
public void run()
{
Init();
try
{
Thread.sleep(1000);
}
catch(InterruptedException e)
{
e.toString();
}
}
public static void main(String []args)
{
currentTime ct=new currentTime("系统时间");
new Thread(ct).start();
ct.addWindowListener(
new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
}
);
}
}
程序要实时的显示系统时间,为什么不行?