package fr.iutfbleau.galerie;

import javax.swing.*;
import java.awt.*;
import java.io.InputStream;
import javax.imageio.ImageIO;

public class Galerie {

    static ClassLoader loader = Thread.currentThread().getContextClassLoader();

    private static String[] paths = {
        "house", "info", "ok", "mail", "whatsapp"
    };

    private static int count = -1;
    private static JLabel lb;
    private static JFrame window;
    
    public static void update(boolean increment) {
        count += increment ? 1 : -1;
        if (count == -1) {
            count = paths.length-1;
        }
        count %= paths.length;
        
        if (lb != null) window.remove(lb);

        try {
            InputStream is = loader.getResourceAsStream("images/" + paths[count] + ".png");
            lb = new JLabel(new ImageIcon(ImageIO.read(is)));
            lb.addMouseListener(new GalleryListener());
            window.add(lb, BorderLayout.CENTER);
            window.revalidate();
        } catch (Exception e) {
            System.out.println("E");
        }
    }

    public static void main(String[] args) {
        window = new JFrame("Galerie");
        window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        window.setSize(650, 650);
        window.setLocation(200, 200);   
        window.setVisible(true);

        Galerie.update(true);
    }
}