DEV/DEV3.2/TP3/Luminance/Luminance.java

52 lines
1.5 KiB
Java
Raw Permalink Normal View History

2023-10-27 14:58:17 +02:00
import java.awt.Graphics;
import java.awt.Color;
import javax.swing.*;
import java.awt.event.*;
import java.util.*;
public class Luminance extends JPanel implements MouseListener{
public Luminance(){
super();
}
boolean listenoncréer = true;
protected void paintComponent(Graphics pinceau) {
// obligatoire : on cree un nouveau pinceau pour pouvoir le modifier plus tard
Graphics pinceau2 = pinceau.create();
List<Integer> paralleloliste = new ArrayList<>();
int color;
if (this.isOpaque()) {
// obligatoire : on repeint toute la surface avec la couleur de fond
pinceau2.setColor(Color.DARK_GRAY);
pinceau2.fillRect(0, 0, this.getWidth(), this.getHeight());
} if(listenoncréer){
for (int i=0; i<30; i++){
Random rand = new Random();
color = rand.nextInt(256);
paralleloliste.add(i,color);
} listenoncréer = false;
} for (int i=0; i<10; i++){
int x[] = {0+(this.getWidth()/11)*i,80+(this.getWidth()/11)*i,180+(this.getWidth()/11)*i,100+(this.getWidth()/11)*i};
int y[] = {this.getHeight()-10,10,10,this.getHeight()-10};
pinceau2.setColor(new Color(paralleloliste.get(0+3*i),paralleloliste.get(1+3*i),paralleloliste.get(2+3*i)));
pinceau2.fillPolygon(x,y,4);
}
}
public void mouseClicked(MouseEvent e){
}
public void mouseEntered(MouseEvent e){
}
public void mouseExited(MouseEvent e){
}
public void mousePressed(MouseEvent e){
}
public void mouseReleased(MouseEvent e){
}
}