This commit is contained in:
2024-03-05 12:52:55 +01:00
parent c367c35d94
commit 77aea5b825
18 changed files with 365 additions and 14 deletions

Binary file not shown.

View File

@@ -0,0 +1,30 @@
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);
}
}
}
}

Binary file not shown.

View File

@@ -0,0 +1,23 @@
import javax.swing.*;
import java.awt.*;
public class Test {
public static void main(String[] args) {
// Création de la fenêtre
JFrame fenetre = new JFrame("Test du dessin");
fenetre.setSize(500,500);
fenetre.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
// Création d'une instance de la classe Sablier
Sablier formes = new Sablier();
// Ajout du panel à la fenêtre
fenetre.add(formes);
// Définition de la taille de la fenêtre
fenetre.setSize(300, 200);
// Rendre la fenêtre visible
fenetre.setVisible(true);
}
}