1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
| import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.applet.*;
public class Mosaique extends Applet {
private Image image;
public void init(String[] args) {
MediaTracker tracker = new MediaTracker(this);
image = getImage(getCodeBase(),"balle.gif");
tracker.addImage(image,1);
try {
tracker.waitForAll();
}
catch (InterruptedException exception) {}
}
// Dessine l'image
public void paint(Graphics g) {
int imageWidth = image.getWidth(this);
int imageHeight = image.getHeight(this);
// Dessine l'image en haut a gauche
g.drawImage(image, 0, 0, null);
// Copie l'image dans tout le panel
for (int i = 0; i * imageWidth <= getWidth(); i++)
for (int j = 0; j * imageHeight <= getHeight(); j++)
if (i + j > 0)
g.copyArea(0, 0, imageWidth, imageHeight,
i * imageWidth, j * imageHeight);
}
} |
Partager