47 lines
1.1 KiB
Java
47 lines
1.1 KiB
Java
/*Emmanuel SRIVASTAVA-TIAMZON*/
|
|
|
|
import javax.swing.*;
|
|
import java.awt.*;
|
|
|
|
public class Illumination extends JComponent {
|
|
|
|
private int niveau;
|
|
private JPanel panel;
|
|
|
|
public Illumination(int niveau) {
|
|
super();
|
|
this.niveau = niveau;
|
|
}
|
|
|
|
public int setNiveau(int newNiveau) {
|
|
if (newNiveau < 0) {
|
|
this.niveau = 0;
|
|
} else if (newNiveau > 10) {
|
|
this.niveau = 10;
|
|
} else {
|
|
this.niveau = newNiveau;
|
|
}
|
|
repaint();
|
|
}
|
|
|
|
public int getNiveau() {
|
|
return this.niveau;
|
|
}
|
|
|
|
@Override
|
|
protected void paintComponent(Graphics pinceau) {
|
|
Graphics secondPinceau = pinceau.create();
|
|
if (this.isOpaque()){
|
|
secondPinceau.setColor(this.getBackground);
|
|
secondPinceau.fillRect(0,0,this.getWidth(),this.getHeight());
|
|
}
|
|
|
|
this.panel.setBackground(Color.BLACK);
|
|
if(this.niveau >= 0) {
|
|
this.panel.setBackground(Color.WHITE);
|
|
} else {
|
|
this.panel.setBackground(Color.BLACK);
|
|
}
|
|
}
|
|
|
|
} |