Files
apl/APL2.1/TP6_Dessin/tp06/Sablier.java
unknown d9949b5cb0 a
2022-01-14 06:54:18 +01:00

34 lines
975 B
Java

import javax.swing.JComponent;
import java.awt.*;
public class Sablier extends JComponent
{
public Sablier()
{
super();
}
@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());
}
Polygon poly1 = new Polygon();
poly1.addPoint(0, 0);
poly1.addPoint(this.getWidth(), 0);
poly1.addPoint(this.getWidth()/2, this.getHeight()/2);
Polygon poly2 = new Polygon();
poly2.addPoint(0, this.getHeight());
poly2.addPoint(this.getWidth(), this.getHeight());
poly2.addPoint(this.getWidth()/2, this.getHeight()/2);
secondPinceau.setColor(Color.CYAN);
secondPinceau.fillPolygon(poly1);
secondPinceau.fillPolygon(poly2);
}
}