import javax.swing.JComponent; import java.awt.Graphics; import java.awt.Color; import java.awt.Polygon; public class Disque extends JComponent { private boolean choix = true; public Disque(){ } @Override protected void paintComponent(Graphics pinceau) { // obligatoire : on crée un nouveau pinceau pour pouvoir le modifier plus tard Graphics secondPinceau = pinceau.create(); // obligatoire : si le composant n'est pas censé être transparent if (this.isOpaque()) { // obligatoire : on repeint toute la surface avec la couleur de fond secondPinceau.setColor(this.getBackground()); secondPinceau.fillRect(0, 0, this.getWidth(), this.getHeight()); } Color majenta = new Color(255,0,255); if (this.choix == true) { // maintenant on dessine ce que l'on veut secondPinceau.setColor(Color.GREEN); secondPinceau.fillRect(0,0,this.getWidth(),this.getHeight()); secondPinceau.setColor(majenta); secondPinceau.fillOval(0,0,this.getWidth(), this.getHeight()); } else if(this.choix == false) { int[] x = {0,this.getWidth(),0,this.getWidth(),0}; int[] y = {0,0,this.getHeight(),this.getHeight(),0}; secondPinceau.setColor(Color.GREEN); secondPinceau.fillRect(0,0,this.getWidth(),this.getHeight()); secondPinceau.setColor(majenta); Polygon sablier = new Polygon(x,y,4); secondPinceau.fillPolygon(sablier); } } public void Change(boolean change){ this.choix = change; } }