TP3
This commit is contained in:
41
DEV2.1/TP14/02_Couleurs/Composant.java
Normal file
41
DEV2.1/TP14/02_Couleurs/Composant.java
Normal file
@@ -0,0 +1,41 @@
|
||||
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);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user