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

public class Playlist extends JFrame implements MouseListener {
    private JLabel etiquette;
    
    @Override
    public void mouseClicked(MouseEvent e) {
        JLabel label = (JLabel) e.getComponent();
        label.setBackground(Color.LIGHT_GRAY);
        this.etiquette.setBackground(Color.WHITE);
        this.etiquette = label;
        repaint();
    }

    @Override
    public void mouseEntered(MouseEvent e) {
        JLabel label = (JLabel) e.getComponent();
        label.setBackground(Color.CYAN);
        repaint();
    }

    @Override
    public void mouseExited(MouseEvent e) {
        JLabel label = (JLabel) e.getComponent();
        if (this.etiquette != label){
            label.setBackground(Color.WHITE);
        }else if (this.etiquette == label){
            label.setBackground(Color.LIGHT_GRAY);
        }
        repaint();
    }

    // Les méthodes suivantes ne sont pas utilisées mais doivent être implémentées en raison de l'interface MouseListener
    @Override
    public void mousePressed(MouseEvent e) {}

    @Override
    public void mouseReleased(MouseEvent e) {}

    public Playlist() {
        super("Playlist");
        setSize(300, 200);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setLayout(new GridLayout(9, 1));

        JLabel mus1 = new JLabel("Speak To Me/Breathe");
        JLabel mus2 = new JLabel("On The Run");
        JLabel mus3 = new JLabel("Time");
        JLabel mus4 = new JLabel("The Great Gig in The Sky");
        JLabel mus5 = new JLabel("Money");
        JLabel mus6 = new JLabel("Us And Them");
        JLabel mus7 = new JLabel("Any Colour You Like");
        JLabel mus8 = new JLabel("Brain Damage");
        JLabel mus9 = new JLabel("Eclipse");

        JLabel[] tab = {mus1, mus2, mus3, mus4, mus5, mus6, mus7, mus8, mus9};

        for (JLabel label : tab) {
            label.setOpaque(true);
            label.addMouseListener(this);
            add(label);
        }

        setVisible(true);
    }

    public static void main(String[] args) {
        Playlist play = new Playlist();
    }
}