// 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.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.SwingUtilities;

public class PicSwap2 extends JFrame {
    private JButton pic;
    private int ix;
    private String[] fnm = { "C:\\red.jpg", "C:\\green.jpg", "C:\\blue.jpg"};
    private void update() {
        pic.setIcon(new ImageIcon(fnm[ix]));
        ix = (ix + 1) % fnm.length;
    }
    public PicSwap2() {
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setTitle("Picture swap");
        getContentPane().setLayout(new BorderLayout());
        pic = new JButton();
        pic.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                update();
            }
        });
        getContentPane().add(pic, BorderLayout.CENTER);
        ix = 0;
        update();
        pack();
    }
    public static void main(String[] args) {
        SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                JFrame f = new PicSwap2();
                f.setVisible(true);
            }
        });
    }
}
