Update DEV.2.1/TP/TP8-Evenements/2.Attente/Attente.java
This commit is contained in:
@@ -1,37 +1,55 @@
|
||||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
import javax.swing.*;
|
||||
|
||||
public class Attente extends JComponent implements WindowsListener {
|
||||
public Attente() {
|
||||
super();
|
||||
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());
|
||||
@Override
|
||||
protected void paintComponent(Graphics pinceau) {
|
||||
Graphics secondPinceau = pinceau.create();
|
||||
secondPinceau.setColor(this.getForeground());
|
||||
|
||||
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);
|
||||
}
|
||||
if (enArrierePlan) {
|
||||
// Dessine un sablier
|
||||
secondPinceau.setColor(Color.BLACK);
|
||||
int[] xHaut = {100, 150, 200};
|
||||
int[] yHaut = {100, 150, 100};
|
||||
int[] xBas = {100, 150, 200};
|
||||
int[] yBas = {250, 200, 250};
|
||||
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
|
||||
protected void windowDeactivated(WindowEvent evenement) {
|
||||
System.out.println("Fenetre arri pl")
|
||||
}
|
||||
@Override
|
||||
public void windowDeactivated(WindowEvent evenement) {
|
||||
System.out.println("Fenêtre mise en arrière-plan !");
|
||||
enArrierePlan = true;
|
||||
repaint();
|
||||
}
|
||||
|
||||
@Override public void windowActivated(WindowsEvent e) {}
|
||||
@Override public void windowOpened(WindowsEvent e) {}
|
||||
@Override public void windowClosing(WindowsEvent e) {}
|
||||
@Override public void windowClosed(WindowsEvent e) {}
|
||||
@Override public void windowIconified(WindowsEvent e) {}
|
||||
@Override public void windowDeiconified(WindowsEvent e) {}
|
||||
}
|
||||
@Override
|
||||
public void windowActivated(WindowEvent e) {
|
||||
System.out.println("Fenêtre active !");
|
||||
enArrierePlan = false;
|
||||
repaint();
|
||||
}
|
||||
|
||||
// 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) {}
|
||||
}
|
||||
|
Reference in New Issue
Block a user