BUT2/DEV/DEV3.2/TP05_Files/Dessin.java

29 lines
683 B
Java
Raw Permalink Normal View History

2023-11-20 13:22:30 +01:00
import javax.swing.*;
import java.awt.*;
public class Dessin extends JComponent {
public Color couleur;
public Dessin(Color couleur){
this.couleur = couleur;
}
public void setColor(Color couleur){
this.couleur = couleur;
this.repaint();
}
@Override
protected void paintComponent(Graphics pinceau) {
Graphics secondPinceau = pinceau.create();
Color couleurFond = this.getBackground();
if (this.isOpaque()) {
secondPinceau.setColor(couleurFond);
secondPinceau.fillRect(0, 0, this.getWidth(), this.getHeight());
}
secondPinceau.setColor(this.couleur);
secondPinceau.fillRect(2,2, this.getWidth()-2, this.getHeight()-2);
}
}