49 lines
1.4 KiB
Java
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);
|
||
|
}
|
||
|
}
|