Files
DEV/DEV2.1/TP06/Sautoir.java
Simoes Lukas 080e0022b8 Fin du TP06
2025-02-16 23:19:06 +01:00

38 lines
1.3 KiB
Java

import java.awt.*;
import javax.swing.*;
public class Sautoir extends JComponent {
@Override
protected void paintComponent(Graphics pinceau) {
// obligatoire : on crée un nouveau pinceau pour pouvoir le modifier plus tard
Graphics secondPinceau = pinceau.create();
// obligatoire : si le composant n'est pas censé être transparent
if (this.isOpaque()) {
// obligatoire : on repeint toute la surface avec la couleur de fond
secondPinceau.setColor(this.getBackground());
secondPinceau.fillRect(0, 0, this.getWidth(), this.getHeight());
}
int[] coord_x = {0, this.getWidth(), 0, this.getWidth()};
int[] coord_y = {0, 0, this.getHeight(), this.getHeight()};
Polygon p = new Polygon(coord_x, coord_y, 4);
secondPinceau.setColor(Color.CYAN);
secondPinceau.fillPolygon(p);
}
public static void main(String[] args) {
JFrame fenetre = new JFrame();
GridLayout layout = new GridLayout(5, 5);
// on configure la fenetre
fenetre.setSize(250, 250);
fenetre.setLocation(0, 0);
fenetre.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
fenetre.setLayout(layout);
for (int i = 0; i != 25; i++) {
fenetre.add(new Sautoir());
}
fenetre.setVisible(true);
}
}