import javax.swing.*;
import java.util.*;
import java.awt.*;
public class Timer extends JFrame implements Runnable
{
String str=new String();
JLabel lab=new JLabel();
Date date=new Date();
Thread time;
Timer()
{
setTitle("时间");
setSize(200,200);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JPanel pan=new JPanel();
pan.setLayout(new GridLayout());
pan.add(lab);
setContentPane(pan);
time=new Thread(this);
time.start();
}
public void run()
{
while (true) {
repaint();
try {
Thread.sleep(1000);
str=new String(date.getHours()+":"+date.getMinutes()+":"+date.getSeconds());
lab.setText(str);
}
catch (InterruptedException ex) {
}
}
}
public static void main(String[] args)
{
Timer timer=new Timer();
timer.setVisible(true);
}
}只能显示,不更新.帮帮忙