第1个回答 2008-12-19
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.util.*;
import java.util.concurrent.*;
public class Clock extends JFrame implements Runnable {
private JLabel label = new JLabel();
public Clock() {
this("Q6");
label.setFont(new Font("Dialog", Font.BOLD, 72));
flush();
this.add(label);
this.pack();
ExecutorService exec = Executors.newCachedThreadPool();
exec.execute(this);
}
public static void main(String[] args) {
Clock c = new Clock();
c.setVisible(true);
}
private void flush() {
String strTime = String.format("%tT", new Date());
label.setText(strTime);
}
public void run() {
while(true) {
flush();
try {
Thread.sleep(1000);
} catch(Exception e) {}
}
}
}