Bonjour,


Mon deuxieme probleme, cè comment arretter mon animation et le faire reprendre avec un clic de la souris, et comment controler la vitesse de l'animation...?



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
 
 
public class AnimImagesRun extends Applet implements Runnable {
Image[] img = new Image[8];
int i=0;
int a=0, b=50;
int j = 0;
Thread thread ;
 
@Override
public void init() {
 
for ( i=0; i < 8; i++) {
 
img[i] = getImage(getCodeBase(), "images/image"+(j+1)+".gif");
j++;
 
}
 
}
@Override
public void start() {
(thread = new Thread(this)).start();
}
 
@Override
public void stop() {
System.out.println("Appel de Stop");
if (thread != null)
thread = null;
} // stop ()
 
 
 
@Override
public void paint(Graphics g) {
g.drawImage(img[i], a, b, this);
}
 
public void run() {
int delay = 1000; // 1 seconde
try {
while (thread == Thread.currentThread()) {
i = (i+1)%img.length;
repaint();
Thread.sleep(delay);
}}
catch (Exception e) {
}
 
 
 
}}