import java.awt.*; public class Anim2 extends java.applet.Applet implements Runnable { // ----------------------------------------------- // Objets communs aux méthodes de la classe Anim // ----------------------------------------------- Image Im[] = new Image[10]; Image Ima; // Image en cours de visualisation Thread t; public void init() // ------------------- // Lecture des images // ------------------- { for (int i=0; i<10; i++) Im[i] = getImage(getCodeBase(),"b"+Integer.toString(i, 10)+".jpg"); setBackground(Color.white); } public void start() // -------------------------- // Mise en place d'un thread // -------------------------- { if (t == null) { t = new Thread(this); t.start(); } } public void stop() // ----------------------- // Suppression du thread // ----------------------- { if (t != null) { t.stop(); t = null; } } public void run() // ------------------------------------------------- // Affichage permanent des 10 images de l'animation // ------------------------------------------------- { while (true) { for (int i=0; i<10; i++) { Ima = Im[i]; repaint(); try { Thread.sleep(250); } catch (InterruptedException ie) { } } } } public void update(Graphics g) // ----------------------------------------------------- // Suppression de l'effacement dans la méthode update() // ----------------------------------------------------- { paint(g); } public void paint(Graphics g) // ------------------------- // Affichage d'une image // ------------------------- { g.drawImage(Ima, 0, 0, this); } }