27 lines
701 B
Java
27 lines
701 B
Java
import java.awt.*;
|
|
import javax.swing.*;
|
|
|
|
public class Triangle extends JComponent {
|
|
|
|
private Color couleur;
|
|
|
|
public Triangle(Color couleur) {
|
|
super();
|
|
this.couleur = couleur;
|
|
}
|
|
|
|
@Override
|
|
public void paintComponent(Graphics pinceau) {
|
|
Graphics secondPinceau = pinceau.create();
|
|
|
|
if (this.isOpaque()) {
|
|
secondPinceau.setColor(this.getBackground());
|
|
secondPinceau.fillRect(0, 0, this.getWidth(), this.getHeight());
|
|
}
|
|
|
|
secondPinceau.setColor(this.couleur);
|
|
int[] coordTriangleX = {0, this.getWidth(), this.getWidth()/2};
|
|
int[] coordTriangleY = {this.getHeight()/3, this.getHeight()/4*3, this.getHeight()};
|
|
secondPinceau.fillPolygon(coordTriangleX, coordTriangleY, 3);
|
|
}
|
|
} |