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

public class Attente extends JComponent implements WindowListener {
    private boolean enArrierePlan = false;

    public Attente() {
        super();
    }

    @Override
    protected void paintComponent(Graphics pinceau) {
        Graphics secondPinceau = pinceau.create();
        secondPinceau.setColor(this.getForeground());

        if (enArrierePlan) {
            int col = 5;
            int ligne = 5;
            int caseWidth = getWidth() / col;
            int caseHeight = getHeight() / ligne;
            secondPinceau.setColor(Color.CYAN);
            int[] xPoints = {0,caseWidth * col, 0, caseWidth * col};
            int[] yPoints = {0,0,caseHeight * ligne, caseHeight * ligne};
            secondPinceau.fillPolygon(xPoints, yPoints, 4);
        } else {
            secondPinceau.setColor(Color.GREEN);
            secondPinceau.fillRect(0, 0, getWidth(), getHeight());
            secondPinceau.setColor(Color.MAGENTA);
            secondPinceau.fillOval(100, 100, 100, 100);
        }
    }

    @Override
    public void windowDeactivated(WindowEvent evenement) {
        System.out.println("Fenêtre mise en arrière-plan");
        enArrierePlan = true;
        repaint();
    }

    @Override
    public void windowActivated(WindowEvent e) {
        System.out.println("Fenêtre active");
        enArrierePlan = false;
        repaint();
    }

    @Override public void windowOpened(WindowEvent e) {}
    @Override public void windowClosing(WindowEvent e) {}
    @Override public void windowClosed(WindowEvent e) {}
    @Override public void windowIconified(WindowEvent e) {}
    @Override public void windowDeiconified(WindowEvent e) {}
}
