TickTockInner.java Source code

Java tutorial

Introduction

Here is the source code for TickTockInner.java

Source

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JOptionPane;
import javax.swing.Timer;

public class TickTockInner {
    public static void main(String[] args) {
        TickTockInner t = new TickTockInner();
        t.go();
    }

    private void go() {
        Timer t = new Timer(1000, new Ticker());
        t.start();
        JOptionPane.showMessageDialog(null, "Click OK to exit program");
        System.exit(0);
    }

    class Ticker implements ActionListener {
        private boolean tick = true;

        public void actionPerformed(ActionEvent event) {
            if (tick) {
                System.out.println("Tick...");
            } else {
                System.out.println("Tock...");
            }
            tick = !tick;
        }
    }
}