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

49 lines
1.4 KiB
Java

import javax.swing.*;
import java.awt.*;
public class Sautoir extends JComponent{
public Sautoir(){
super();
}
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 sablier = new Polygon();
secondPinceau.setColor(Color.BLACK);
//definition des differents points
sablier.addPoint(0,0);// en haut a gauche
sablier.addPoint(this.getWidth(),0); // en haut a droite
sablier.addPoint(this.getWidth()/2,this.getHeight()/2); // au millieu
sablier.addPoint(0,this.getHeight());// en bas a gauche
sablier.addPoint(this.getWidth(),this.getHeight()); //en bas a droite
secondPinceau.fillPolygon(sablier); // on remplie le sablier
}
public static void main(String[] args){
JFrame fenetre = new JFrame();
fenetre.setSize(500,500);
fenetre.setLocation(100,100);
fenetre.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
GridLayout grille = new GridLayout(5,5);
fenetre.setLayout(grille);
for(int i=0; i<25; i++){
fenetre.add(new Sautoir());
}
fenetre.setVisible(true);
}
}