我做了一个数字时钟。但它不能正常工作。
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.util.Date;
public class DigitalClock extends JFrame implements ActionListener {
JLabel l1 = new JLabel();
Timer t;
public DigitalClock() {
super("Digital Clock");
l1.setFont( new Font("Verdana",Font.BOLD,11) );
l1.setHorizontalAlignment( JLabel.RIGHT);
l1.setVerticalAlignment( JLabel.BOTTOM);
t = new Timer(1000,this);
getContentPane().add(l1);
setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
setSize(110,100);
setVisible(true);
// call actionPerformed to get Time at the startup
actionPerformed(null);
}
public void actionPerformed(ActionEvent evt) {
l1.setText( new Date().toString().substring(11,19));
}
public static void main(String args[]) {
new DigitalClock();
}
} // end of class
我做了一个数字时钟。但它不能正常工作。
帮帮我,我找不到问题..
请帮助..
output is constant time