提示:您可在线编辑运行本教程的实例 - 运行实例,去试试!
使用接口实现回调模式
import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.JOptionPane; /* 时 代 J a v a */ import javax.swing.Timer; public class TickTock { public static void main(String[] args) { Timer t = new Timer(1000, new Ticker()); t.start(); // display a message box to prevent the program from ending immediately JOptionPane.showMessageDialog(null, "Click OK to exit program"); }/*来 自 时 代 Java - nowjava.com*/ } class Ticker implements ActionListener { private boolean tick = true; public void actionPerformed(ActionEvent event) { if (tick