我正在尝试使用 Swing Timer 重复打印一个语句,但该语句没有被打印出来!
我犯了什么错误?
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.Timer;
public class SwingTimer implements ActionListener {
Timer timer;
public static void main(String[] args) {
SwingTimer obj = new SwingTimer();
obj.create();
}
public void create() {
timer = new Timer(1000, this);
timer.setInitialDelay(0);
timer.start();
}
@Override
public void actionPerformed(ActionEvent e) {
System.out.println("Hello using Timer");
}
}