import java.awt.*; import java.awt.event.*; import javax.swing.*; public class Observer implements MouseListener { private JLabel prevSelected; public void mouseClicked(MouseEvent evenement) { JLabel lb = (JLabel)evenement.getSource(); if (prevSelected != null) { prevSelected.setBackground(new Color(255, 255, 255)); } lb.setBackground(new Color(0, 255, 255)); prevSelected = lb; } public void mouseEntered(MouseEvent evenement) { JLabel lb = (JLabel)evenement.getSource(); if (lb == prevSelected) { lb.setBackground(new Color(0, 255, 255)); } else { lb.setBackground(new Color(200, 200, 200)); } } public void mouseExited(MouseEvent evenement) { JLabel lb = (JLabel)evenement.getSource(); if (lb == prevSelected) { lb.setBackground(new Color(0, 200, 255)); } else { lb.setBackground(new Color(255, 255, 255)); } } public void mousePressed(MouseEvent evenement) {} public void mouseReleased(MouseEvent evenement) {} }