apl/APL2.1/TP9_Evenements(suite)/Cercle.java

38 lines
972 B
Java
Raw Permalink Normal View History

2022-01-14 06:54:18 +01:00
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class Cercle extends JComponent{
private int volume;
public Cercle(){
super();
this.volume=0;
}
public void setVolume(int volume){
this.volume=volume;
}
protected void paintComponent(Graphics pinceau){
Graphics secondPinceau = pinceau.create();
if (this.isOpaque()){
secondPinceau.setColor(this.getBackground());
secondPinceau.fillRect(0, 0, this.getWidth(), this.getHeight());
}
secondPinceau.setColor(Color.BLACK);
secondPinceau.fillRect(0,0,this.getWidth(), this.getHeight());
secondPinceau.setColor(Color.YELLOW);
for(int i=0;i<this.volume;i++){
secondPinceau.fillOval(100*i,50,50,50);
}
secondPinceau.setColor(Color.GRAY);
for(int i=0;i<10-this.volume;i++){
secondPinceau.fillOval(100*i+this.volume*100,50,50,50);
}
}
}