BUT2/DEV/DEV2.1/TP06_Dessin/Q2_Sautoir/Sablier.java~

37 lines
1.2 KiB
Java
Raw Permalink Normal View History

2023-10-23 13:23:36 +02:00
import javax.swing.*;
import java.awt.*;
public class AfficheImage extends JComponent {
public int numColone;
public int numLigne;
public static int nbColone = 5;
public static int nbLigne = 5;
public AfficheImage(int numColone, int numLigne) {
super();
this.numColone = numColone;
this.numLigne = numLigne;
}
@Override
protected void paintComponent(Graphics pinceau) {
Graphics secondPinceau = pinceau.create();
int longueur = this.getWidth();
int hauteur = this.getHeight();
if (this.isOpaque()) {
secondPinceau.setColor(this.getBackground());
secondPinceau.fillRect(0, 0, longueur, hauteur);
}
int uniteX = longueur/this.nbColone;
int uniteY = hauteur/this.nbLigne;
int[] triangleXHaut = {this.numColone*UniteX , (this.numColone+1)*UniteX , this.numColone*UniteX+UniteX/2};
int[] triangleYHaut = {};
int[] triangleXBas = {this.numColone*UniteX , (this.numColone+1)*UniteX , this.numColone*UniteX+UniteX/2};
int[] triangleYBas = {};
secondPinceau.setColor(new Color(255,100,0));
secondPinceau.fillPolygon(triangleXHaut, triangleYHaut, 3);
secondPinceau.fillPolygon(triangleXBas, triangleYBas, 3);
}
}