Files
DEV/DEV.2.1/CM1/ex4/Illumination.java

47 lines
1.1 KiB
Java
Raw Normal View History

2025-09-30 09:43:41 +02:00
/*Emmanuel SRIVASTAVA-TIAMZON*/
2025-03-10 17:31:32 +01:00
import javax.swing.*;
import java.awt.*;
2025-09-30 09:43:41 +02:00
public class Illumination extends JComponent {
private int niveau;
private JPanel panel;
2025-03-10 17:31:32 +01:00
2025-09-30 09:43:41 +02:00
public Illumination(int niveau) {
2025-03-10 17:31:32 +01:00
super();
2025-09-30 09:43:41 +02:00
this.niveau = niveau;
2025-03-10 17:31:32 +01:00
}
2025-09-30 09:43:41 +02:00
public int setNiveau(int newNiveau) {
2025-03-16 11:33:42 +01:00
if (newNiveau < 0) {
this.niveau = 0;
} else if (newNiveau > 10) {
this.niveau = 10;
} else {
this.niveau = newNiveau;
}
repaint();
}
public int getNiveau() {
return this.niveau;
}
2025-03-10 17:31:32 +01:00
@Override
protected void paintComponent(Graphics pinceau) {
Graphics secondPinceau = pinceau.create();
2025-03-16 11:33:42 +01:00
if (this.isOpaque()){
secondPinceau.setColor(this.getBackground);
secondPinceau.fillRect(0,0,this.getWidth(),this.getHeight());
}
2025-09-30 09:43:41 +02:00
this.panel.setBackground(Color.BLACK);
if(this.niveau >= 0) {
this.panel.setBackground(Color.WHITE);
} else {
this.panel.setBackground(Color.BLACK);
}
2025-03-10 17:31:32 +01:00
}
}