BUT2/DEV/DEV2.1/Controle_Machine_blanc/Q4_Modelisation/Tuile.java

29 lines
780 B
Java
Raw Permalink Normal View History

2023-10-23 13:23:36 +02:00
import javax.swing.*;
import java.awt.*;
public class Tuile extends JComponent {
private Image texture;
private int longueur;
private int hauteur;
public Tuile(String cheminImage) {
super();
this.texture = Toolkit.getDefaultToolkit().getImage(cheminImage);
this.longueur = 512;
this.hauteur = 512;
}
@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());
}
for (int y=0; y<this.getHeight(); y+=this.hauteur){
for (int x=0; x<this.getWidth(); x+=this.longueur){
secondPinceau.drawImage(this.texture, x, y, this);
}
}
}
}