BUT2/DEV/DEV2.1/TP08_Evenement/Q2_Attente/Evenement.java~

40 lines
1.3 KiB
Java
Raw Permalink Normal View History

2023-10-23 13:23:36 +02:00
public class Evenement implements WindowListener extends JComponent{
public int etat;
public Evenement(){
this.etat = 1;
}
@Override
protected void paintComponent(Graphics pinceau) {
Graphics secondPinceau = pinceau.create();
int longueur = this.getWidth();
int hauteur = this.getHeight();
secondPinceau.setColor(Color.GREEN);
secondPinceau.fillRect(0, 0, longueur, hauteur);
secondPinceau.setColor(Color.MAGENTA);
if (this.etat==1){
secondPinceau.fillOval(0,0,longueur,hauteur);
}
if (this.etat==2){
int[] triangleXHaut = {0, longueur, longueur/2};
int[] triangleYHaut = {0, 0, hauteur/2};
int[] triangleXBas = {0, longueur, longueur/2};
int[] triangleYBas = {hauteur, hauteur, hauteur/2};
secondPinceau.fillPolygon(triangleXHaut, triangleYHaut, 3);
secondPinceau.fillPolygon(triangleXBas, triangleYBas, 3);
}
}
public void windowActivated(WindowEvent evenement){
this.etat=1;
}
public void windowClosed(WindowEvent evenement){}
public void windowClosing(WindowEvent evenement){}
public void windowDeactivated(WindowEvent evenement){
this.etat=2;
}
public void windowDeiconified(WindowEvent evenement){}
public void windowIconified(WindowEvent evenement){}
public void windowOpened(WindowEvent evenement){}
}