DEV_BUT1/DEV2.1/TP06/Sablier.java
2023-04-04 14:03:16 +02:00

39 lines
1.1 KiB
Java

import javax.swing.*;
import java.awt.*;
public class Sablier extends JComponent{
private int[] xPoints;
private int[] yPoints;
private int[] yPoints2;
public Sablier(){
super();
this.xPoints = new int[3];
this.yPoints = new int[3];
this.yPoints2 = new int[3];
}
@Override
protected void paintComponent(Graphics pinceau) {
Graphics secondPinceau = pinceau.create();
if (this.isOpaque()) {
secondPinceau.setColor(this.getBackground());
secondPinceau.fillRect(0, 0, this.getWidth(), this.getHeight());
}
this.xPoints[0] = 0;
this.xPoints[1] = this.getWidth()/2;
this.xPoints[2] = this.getWidth();
this.yPoints[0] = 0;
this.yPoints[1] = this.getHeight()/2;
this.yPoints[2] = 0;
this.yPoints2[0] = this.getHeight();
this.yPoints2[1] = this.getHeight()/2;
this.yPoints2[2] = this.getHeight();
secondPinceau.setColor(Color.CYAN);
secondPinceau.drawPolygon(xPoints, yPoints, 3);
secondPinceau.fillPolygon(xPoints, yPoints, 3);
secondPinceau.drawPolygon(xPoints, yPoints2, 3);
secondPinceau.fillPolygon(xPoints, yPoints2, 3);
}
}