Update DEV.2.1/TP/TP8-Evenements/2.Attente/Attente.java

This commit is contained in:
2025-03-05 21:25:34 +01:00
parent 75e5c6f843
commit 4c29d2b40a

View File

@@ -1,37 +1,55 @@
import java.awt.*; import java.awt.*;
import java.awt.event.*; import java.awt.event.*;
import javax.swing.*; import javax.swing.*;
public class Attente extends JComponent implements WindowsListener { public class Attente extends JComponent implements WindowListener {
public Attente() { private boolean enArrierePlan = false;
super();
} public Attente() {
super();
}
@Override @Override
protected void paintComponent(Graphics pinceau) { protected void paintComponent(Graphics pinceau) {
Graphics secondPinceau = pinceau.create(); Graphics secondPinceau = pinceau.create();
secondPinceau.setColor(this.getForeground()); secondPinceau.setColor(this.getForeground());
int col = 5; if (enArrierePlan) {
int ligne = 5; // Dessine un sablier
int caseWidth = getWidth() / col; secondPinceau.setColor(Color.BLACK);
int caseHeight = getHeight() / ligne; int[] xHaut = {100, 150, 200};
secondPinceau.setColor(Color.CYAN); int[] yHaut = {100, 150, 100};
int[] xPoints = {0,caseWidth * col, 0, caseWidth * col}; int[] xBas = {100, 150, 200};
int[] yPoints = {0,0,caseHeight * ligne, caseHeight * ligne}; int[] yBas = {250, 200, 250};
secondPinceau.fillPolygon(xPoints, yPoints, 4); secondPinceau.fillPolygon(xHaut, yHaut, 3);
} secondPinceau.fillPolygon(xBas, yBas, 3);
} else {
// Dessine un cercle magenta sur fond vert
secondPinceau.setColor(Color.GREEN);
secondPinceau.fillRect(0, 0, getWidth(), getHeight());
secondPinceau.setColor(Color.MAGENTA);
secondPinceau.fillOval(100, 100, 100, 100);
}
}
@Override @Override
protected void windowDeactivated(WindowEvent evenement) { public void windowDeactivated(WindowEvent evenement) {
System.out.println("Fenetre arri pl") System.out.println("Fenêtre mise en arrière-plan !");
} enArrierePlan = true;
repaint();
}
@Override public void windowActivated(WindowsEvent e) {} @Override
@Override public void windowOpened(WindowsEvent e) {} public void windowActivated(WindowEvent e) {
@Override public void windowClosing(WindowsEvent e) {} System.out.println("Fenêtre active !");
@Override public void windowClosed(WindowsEvent e) {} enArrierePlan = false;
@Override public void windowIconified(WindowsEvent e) {} repaint();
@Override public void windowDeiconified(WindowsEvent e) {} }
}
// Méthodes inutilisées mais obligatoires à déclarer
@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) {}
}