38 lines
972 B
Java
38 lines
972 B
Java
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);
|
|
}
|
|
}
|
|
} |