集册 Java实例教程 使用接口实现回调模式

使用接口实现回调模式

欢马劈雪     最近更新时间:2020-01-02 10:19:05

359
提示:您可在线编辑运行本教程的实例 - 运行实例,去试试!
使用接口实现回调模式

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
展开阅读全文