Code :
import java.applet.Applet; import java.awt.Graphics; import java.awt.Image; import java.awt.image.ImageObserver; private static final long serialVersionUID = 1L; private static final String URL_IMAGE = "gfx/image.jpg"; private static final int ETAPES = 40; private static final int DUREE_PAUSE = 100; private int etape; /** * (Ré)initialise l'animation */ public void init() { image = getImage(getCodeBase(), URL_IMAGE); etape = 0; } public void start() { if (runner == null) { runner.start(); } } public void stop() { if (runner != null) { runner.interrupt(); runner = null; } } int w = image.getWidth(this), h = image.getHeight(this); if ((w != -1) && (h != -1)) { w = w * etape / ETAPES; h = h * etape / ETAPES; // Dessine l'image à l'échelle actuelle au centre de l'applet screen.drawImage(image, (getWidth() - w) / 2, (getHeight() - h) / 2, w, h, this); } } public void run() { try { while (etape < ETAPES) { etape++; repaint(); } // Le thread a été interrompu } } @Override public boolean imageUpdate (Image img, int infoflags, int x, int y, int w, int h ) { // Refait une tentative de dessin si les dimensions de l'image sont à présent connues repaint(); } return super.imageUpdate(img, infoflags, x, y, w, h); } }
|