DEV_BUT1/DEV2.1/TP06/Exo2/Sablier.java

36 lines
1.0 KiB
Java
Raw Normal View History

2023-04-04 14:03:16 +02:00
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[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();
}
@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());
}
secondPinceau.setColor(Color.CYAN);
secondPinceau.drawPolygon(xPoints, yPoints, 3);
secondPinceau.fillPolygon(xPoints, yPoints, 3);
secondPinceau.drawPolygon(xPoints, yPoints2, 3);
secondPinceau.fillPolygon(xPoints, yPoints2, 3);
}
}