31 lines
1.0 KiB
Java
31 lines
1.0 KiB
Java
import javax.swing.*;
|
|
import java.awt.*;
|
|
|
|
public class Sablier extends JComponent {
|
|
|
|
// Méthode pour dessiner sur le composant
|
|
@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, 5, 5);
|
|
}
|
|
for (int i = 0; i < 5; i++) {
|
|
for (int j = 0; j < 5; j++) {
|
|
int[] xPoints = {j * (50 + 20),50 + j * (50 + 20),j * (50 + 20),-50 + j * (50 + 20)};
|
|
int[] yPoints = {i * (50 + 20),50 + i * (50 + 20),2 * 50 + i * (50 + 20),50 + i * (50 + 20)};
|
|
|
|
secondPinceau.setColor(new Color(37, 253, 233));
|
|
secondPinceau.fillPolygon(xPoints, yPoints, 4);
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
}
|