OVH Cloud OVH Cloud

Slef Learning - Pourquoi l'image No1 n'apparait elle jamais ?

2 réponses
Avatar
Latyr_Dev
Bonjour

Qui pourrait m'expliquer :
1/ Pourquoi la premiere image n'apparait elle jamais ?
2/ La m=E9thode que j'utilise pour faire une temporisation est elle la=20
bonne ?

Merci d'avance

--------------- Code Start --------------
import java.applet.Applet;
// import java.util.*;
import java.awt.*;

/*
* Cr=E9=E9 le 30 juin 2004
*
* Pour changer le mod=E8le de ce fichier g=E9n=E9r=E9, allez =E0 :
* Fen=EAtre>Pr=E9f=E9rences>Java>G=E9n=E9ration de code>Code e=
t=20
commentaires
*/

/**
* @author JLF928
*
* Pour changer le mod=E8le de ce commentaire de type g=E9n=E9r=E9, allez =
=E0 :
* Fen=EAtre>Pr=E9f=E9rences>Java>G=E9n=E9ration de code>Code e=
t=20
commentaires
*/

public class Album extends Applet {
=09Image[] catalog;
=09Delay delai;
=09
=09public void init(){
=09=09catalog =3D new Image[6];
=09=09delai =3D new Delay();
=09=09
=09=09try {
=09=09=09for(int i=3D0; i<6; i++){
=09=09=09catalog[i]=3Dthis.getImage(this.getDocumentBase(),=20
"img0"+(i+1)+".jpg");
=09=09=09System.out.println("i=3D " +i+ " i+1=3D " +(i+1) );
=09=09=09}
=09=09}
=09=09catch (ArrayIndexOutOfBoundsException e){
=09=09=09System.err.println(e.toString());
=09=09}
=09=09=09=09
=09}
=09public void paint(Graphics g){
=09=09for(int i=3D0; i<6; i++){
=09=09=09System.out.println("Image n0 : " +(i+1));
=09=09=09g.drawImage(catalog[i],0,0,220,180, this);
=09=09=09delai.run();
=09=09}
=09}
=09
=09public void stop(){
=09=09delai.end();
=09}

}

class Delay extends Thread {
=09boolean isStop;
=09
=09public Delay(){
=09=09super();
=09=09isStop =3Dfalse;
=09=09
=09}
=09
=09public void run(){
=09=09double delay=3D800000000;
=09=09while (delay>0 & !isStop){
=09=09=09delay--;
=09=09}
=09}
=09
=09public void end(){
=09=09isStop =3Dtrue;
=09}
}
-------------- Code End -----------------

2 réponses

Avatar
no.bcausse.spam
Latyr_Dev wrote:

Bonjour

Qui pourrait m'expliquer :
1/ Pourquoi la premiere image n'apparait elle jamais ?
2/ La méthode que j'utilise pour faire une temporisation est elle la
bonne ?

Merci d'avance

--------------- Code Start --------------
import java.applet.Applet;
// import java.util.*;
import java.awt.*;

/*
* Créé le 30 juin 2004
*
* Pour changer le modèle de ce fichier généré, allez à :
* Fenêtre&gt;Préférences&gt;Java&gt;Génération de code&gt;Code et
commentaires
*/

/**
* @author JLF928
*
* Pour changer le modèle de ce commentaire de type généré, allez à :
* Fenêtre&gt;Préférences&gt;Java&gt;Génération de code&gt;Code et
commentaires
*/

public class Album extends Applet {
Image[] catalog;
Delay delai;

public void init(){
catalog = new Image[6];
delai = new Delay();

try {
for(int i=0; i<6; i++){
catalog[i]=this.getImage(this.getDocumentBase(),
"img0"+(i+1)+".jpg");
System.out.println("i= " +i+ " i+1= " +(i+1) );
}
}
catch (ArrayIndexOutOfBoundsException e){
System.err.println(e.toString());
}

}
public void paint(Graphics g){
for(int i=0; i<6; i++){
System.out.println("Image n0 : " +(i+1));
g.drawImage(catalog[i],0,0,220,180, this);
delai.run();
}
}

public void stop(){
delai.end();
}

}

class Delay extends Thread {
boolean isStop;

public Delay(){
super();
isStop úlse;

}

public void run(){
double delay€0000000;
while (delay>0 & !isStop){
delay--;
}
}

public void end(){
isStop =true;
}
}
-------------- Code End -----------------


<code survolé>
1) attendre la fin du chargement des images : voir MediaTracker
2) un thread ne peut pas etre relancé (1 seul fois run()), donc creation
d'un nouveau thread
</code survolé>
--
bruno Causse
http://perso.wanadoo.fr/othello

Avatar
Latyr_Dev