Tick Tock with an Inner Class : Timer « Swing JFC « Java

Tick Tock with an Inner Class


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();

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

  class Ticker implements ActionListener {
    private boolean tick = true;

    public void actionPerformed(ActionEvent event) {
      if (tick) {
      } else {
      tick = !tick;


Related examples in the same category

1.Timer: clock labelTimer: clock label
2.Timer SampleTimer Sample
3.Timer with ProgressBar
4.Tick Tock with a Static Inner Class
5.Swing Timer Demo
6.Time Resolution
7.An applet that counts down from a specified time
8.Using swing TimerUsing swing Timer