Files
DEV/DEV2.1/TP14/02_Couleurs/Composant.java
Simoes Lukas 2f94e24111 TP3
2025-03-31 17:29:54 +02:00

41 lines
1.1 KiB
Java

import java.awt.*;
import javax.swing.*;
public class Composant extends JComponent {
private Color couleur1;
private Color couleur2;
private JLabel nomCouleur1;
private JLabel nomCouleur2;
public Composant(Color couleur1, Color couleur2) {
this.couleur1 = couleur1;
this.couleur2 = couleur2;
}
@Override
public void paintComponent(Graphics pinceau) {
Graphics secondPinceau = pinceau.create();
int[] x1 = {0, 0, this.getWidth()};
int[] y1 = {0, this.getHeight(), this.getHeight()};
int[] x2 = {0, this.getWidth(), this.getWidth()};
int[] y2 = {0, 0, this.getHeight()};
secondPinceau.setColor(this.couleur1);
secondPinceau.fillPolygon(x1, y1, 3);
secondPinceau.setColor(this.couleur2);
secondPinceau.fillPolygon(x2, y2, 3);
JLabel couleur1Nom = this.nomCouleur1;
JLabel couleur2Nom = this.nomCouleur2;
couleur1Nom.setHorizontalAlignment(JLabel.RIGHT);
couleur2Nom.setHorizontalAlignment(JLabel.LEFT);
this.setLayout(new BorderLayout());
this.add(couleur1Nom, BorderLayout.NORTH);
this.add(couleur2Nom, BorderLayout.SOUTH);
}
}