Images non affichées dans applet sur serveur distant
Bonjour à tous !
Je bute sur un problème apparemment simple:
J'ai une applet graphique qui fonctionne parfaitement en local avec toutes les versions de windows et la plupart des browsers (explorer, firefox)
Voici le code:
Code:
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
| /*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
import java.applet.Applet;
import java.awt.*;
public class SetGenerator extends Applet {
MySet A;
int Nums[]; // liste des indices des éléments choisis
int n; // nombre d'éléments
int wel = 64; // largeur standard des icones
int hel = 64; // hauteur standard des icones
MediaTracker tracker;
Image elepics[];
String imdir = "PICS/";
Image offImage;
Graphics offGraphics;
int width = 320;// les dimensions de l'écran
int height = 286;
private int posystring() {
return height - 20;
}
private int posxi(int n) {
return (n / 4) * wel;
}
private int posyi(int n) {
return (n % 4) * hel;
}
private void initimages() {
for (int i = 0; i < n; i++) {
elepics[i] = getImage(getDocumentBase(), imdir + MySet.ALL[Nums[i]].filename);
tracker.addImage(elepics[i], i);
}
}
/**
* Initialization method that will be called after the applet is loaded
* into the browser.
*/
@Override
public void init() {
// TODO start asynchronous download of heavy resources
// récupération des paramètres javascript
// de l'applette
String nom = getParameter("Nom");
String strn = getParameter("nbelts");
//n = 1 + ((int) (Math.random() * 50)) % 20;
n = Integer.parseInt(strn);
Nums = new int[n];
for (int i = 0; i < n; i++) {
String sei = getParameter(nom + Integer.toString(i));
int ei = Integer.parseInt(sei);
Nums[i] = ei;
}
// construction de l'objet MySet
A = new MySet(nom, n, Nums);
// initialisation des images
elepics = new Image[n];
tracker = new MediaTracker(this);
initimages();
// fond noir
setBackground(Color.BLACK);
// générer l'image en double buffer
offImage = createImage(width, height);
offGraphics = offImage.getGraphics();
paintFrame(offGraphics);
}
@Override
public void stop() {
offImage = null;
offGraphics = null;
}
public void paintFrame(Graphics g) {
for (int i = 0; i < n; i++) {
g.drawImage(elepics[i], posxi(i), posyi(i), null);
}
g.setColor(Color.WHITE);
Font font = new Font("Arial", Font.PLAIN, 16);
g.setFont(font);
g.drawString(A.to_string(), 0, posystring());
}
// TODO overwrite start(), stop() and destroy() methods
@Override
public void paint(Graphics g) {
if (!tracker.checkAll(true)) {
g.drawString("chargement en cours....", 10, 20);
repaint(100);
return;
}
// recopier le buffer sur l'écran
paintFrame(offGraphics);
g.drawImage(offImage, 0, 0, null);
}
} |
Si je transporte mon site sur un serveur distant, les images ne s'affichent plus. Aucun message d'erreur! bien au contraire Applet loaded, applet started
puis écran noir, par contre le texte s'affiche correctement, autrement dit la fin de paintFrame s'exécute, mais pas le début.
PS: les images danss le sous-répertoire 'PICS' sont accessibles puisqu'elles sont affichées dans la page (hors applet).
Je soupçonne soit le double-buffer (indispensable pour la fluidité), soit le mediatracker, mais je ne comprends pas pourquoi tout marche parfaitement en local.
PPS: Sous linux (Ubuntu-Firefox) en local, c'est aléatoire cela peut fonctionner ou ne pas fonctionner.
Si quelqu'un a une idée.
Merci