日期:2014-05-20 浏览次数:20883 次
public class TimerTest extends JFrame {
public static void main(String[] args) {
new TimerTest();
}
public TimerTest() {
this.setBounds(300, 300, 300, 300);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setVisible(true);
Timer timer = new Timer(1000, new TestActionListener());
timer.setDelay(2000);
timer.start();
System.out.println("start : " + System.currentTimeMillis());
}
}
class TestActionListener implements ActionListener {
public void actionPerformed(ActionEvent e) {
long now = System.currentTimeMillis();
System.out.println(now);
}
}
------解决方案--------------------
setDelay确实是延时,
不过调整首次延时需要用setInitialDelay
------解决方案--------------------
我自己编译了一下怎么可以啊?用setDelay是可以的啊~还有楼主这个简单的程序为什么还要弄个对话框啊~