Je dois rajouté la methode update() a mon animation, mais quand je la met mon animation affiche les images les une par dessus les autre, si j'eleve la methode l'affichage se fait correctement, quelqu'un a une idée de ce que je fait pas correct.

Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
 
 
import java.applet.Applet;
import java.awt.Color;
import java.awt.Event;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.MediaTracker;
 
public class AnimImages extends Applet implements Runnable{ 
	MediaTracker MT; //Initialisation du médiatracker.
   private Image tabImage[]; //création de tabimage.
   private int indexPhoto; //création de l'index.
   Thread AnimImages = null; //création du thread.
 
 
   public void init() { 
 
      // initialisation de l'index des photos.
      indexPhoto=0; 
 
      super.init(); 
      //chargement du tableau d'image 
      tabImage = new Image[9];//initialisation du tableau d'images.
      // mettre le fond d'écran blanc.
       this.setBackground(Color.white);
       //création d'un nouveau mediatracker.
       MT = new MediaTracker(this);
      for (int i = 0; i < tabImage.length; i++) {
 
         try {
       	  tabImage[i] = getImage(getDocumentBase(), "images/guepard" + (i + 1) + ".gif");
       	}
       	catch (Exception e)
       	  {
       	    System.out.println("failed loading Image: " 
       			       + getDocumentBase() + "images/guepard" + (i + 1) + ".gif");
       	  }
       	// On ajoute cette image au MediaTracker.
       	MT.addImage(tabImage[i], i);
 
             }
           // true indique que les images doivent se charger.
           MT.checkAll(true);
         }
 
       public void start()
         {
           // démarre la Thread qui va animer les images.
    	if (AnimImages == null)
       	AnimImages = new Thread(this);
       	AnimImages.start();
         }
 
       public void run()
         {
           // lancement de (start et stop).
           indexPhoto = 0;
           // Pour toujours. Mais on peut en sortir par break;
           while (true)
           {
       	// nombre d'images autorisé.
 
       	if (indexPhoto >= tabImage.length) 
       	  indexPhoto = 0;
       	// Si l'image numero indexPhoto est chargée et si il n'y a pas
       	// eu d'erreur sur cette image
       	if (MT.checkID(indexPhoto) && !MT.isErrorID(indexPhoto))
       	  // peint la zone.
       	  repaint();
       	// Dors 100 ms pour que les autres Threads aient le CPU si
       	// elles le veulent.
       	try { Thread.sleep(100); }
       	catch (InterruptedException e)
       	  { 
       	    // Sort de la boucle while().
       	    break; 
       	  }
       	// Change d'image
       	indexPhoto++;
             }
         }
 
 
       public void stop()
         {
           // arrête l'animation des images.
    	if (AnimImages != null)            
       	AnimImages.stop();
       	AnimImages = null;
             }
 
 
 
       public void paint(Graphics g)
       {
 
       repaint;  
 
       }
 
        public void update(Graphics g) {
                    g.drawImage(tabImage[indexPhoto], 0, 0, this);
    	   g.setColor(getBackground());
    	  g.fillRect(0, 0, WIDTH, HEIGHT);
    	  g.setColor(getForeground());
 
 
 
       }
}
[ Sujet déplacé depuis le forum java par Viena ]
Les Règles du Forum