import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

public class Controller_galerie implements MouseListener{
    private int indice;
    private int max_indice;
    private String[] tab;
    private JFrame page;
    private JLabel image;

    public Controller_galerie(String[] tab){
        this.tab = tab;
        this.indice = 0;
        this.max_indice = this.tab.length-1;
    }

    public void SetPage(JFrame page, JLabel image){
        this.page = page;
        this.image = image;
    }
    
    @Override
    public void mouseClicked(MouseEvent e) {
        Component taille = (Component) e.getComponent();
        if (e.getX()>taille.getWidth()/2){
            if (this.indice == this.max_indice){
                this.indice = 0;
            }else{
                this.indice++;
            }
        }else if (e.getX()<taille.getWidth()/2){
            if (this.indice == 0){
                this.indice = this.max_indice;
            }else{
                this.indice--;
            }
        }
        System.out.println(this.indice);
        System.out.println(taille.getWidth()/2);
        this.page.remove(this.image);
        this.image = new JLabel(new ImageIcon(this.tab[this.indice]));
        this.image.addMouseListener(this);
        this.page.add(this.image);
        this.page.revalidate();
    }

    @Override
    public void mouseEntered(MouseEvent e) {}

    @Override
    public void mouseExited(MouseEvent e) {}

    @Override
    public void mousePressed(MouseEvent e) {}

    @Override
    public void mouseReleased(MouseEvent e) {}
}