/*
  Copyright (c) October 2013 by Paweł Rzechonek
  Program definiuje klasę anonimową do podjęcia obsługi zdarzenia akcji.
  Akcja jest generowana przez obiekt javax.swing.Timer.
  Istotne elementy w programie:
    * implementacja interfejsu ActionListener za pomocą klasy anonimowej;
    * zastosowanie klasy Timer do generowania zdarzeń akcji;
    * usypianie bieżącego wątku za pomocą metody sleep.
*/

import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.Timer;

public class Wyliczanka {

    static ActionListener akcja = new ActionListener() {
        int a=1, b=0, i=0;
        public void actionPerformed (ActionEvent ev) {
            System.out.printf("F_%-2d = %11d\n",i++,b);
            int c = a+b; a = b; b = c;
        }
    };

    public static void main(String[] args) throws InterruptedException {
    	Timer t = new Timer(400,akcja);
        System.out.println("==================");
        Thread.currentThread().sleep(1000);
        t.start();
        Thread.currentThread().sleep(20000);
    	t.stop();
        Thread.currentThread().sleep(1000);
        System.out.println("==================");
    }
}

