// Collection of code snippets by Arne Vajhøj 
// (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) 
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class Virker extends JFrame implements ActionListener {
    private JButton klik;

    private Timer t;

    public Virker() {
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        getContentPane().setLayout(new BorderLayout());
        klik = new JButton("Klik");
        klik.setBackground(Color.GREEN);
        klik.addActionListener(this);
        getContentPane().add(klik, BorderLayout.CENTER);
        pack();
    }

    public void actionPerformed(ActionEvent ev) {
        if (klik.getBackground() == Color.GREEN) {
            klik.setBackground(Color.RED);
            t = new Timer(2000, this);
            t.start();
        } else if (klik.getBackground() == Color.RED) {
            klik.setBackground(Color.YELLOW);
        } else if (klik.getBackground() == Color.YELLOW) {
            t.stop();
            klik.setBackground(Color.GREEN);
        }
    }

    public static void main(String[] args) {
        Virker f = new Virker();
        f.setVisible(true);
    }
}
