[3022] in java-interest
HELP NEEDED: Images Drawn Before Loaded
daemon@ATHENA.MIT.EDU (ian c rogers)
Thu Oct 26 22:55:30 1995
From: "ian c rogers" <irogers@ghostfacekiller.biggun.com>
Date: Thu, 26 Oct 1995 01:05:05 -0700
To: java-interest@java.Eng.Sun.COM
Earlier today thing were working just fine. I played around a bit trying to
add a couple extra threads, and the synch blew up on me...
I'm writing an applet which animates some images based on the Animation applet,
using synchronous notification via a notifyAll() in the updateImage() method.
One of my functions is doing a wait(), and hearing back from the
updateImage(), but the app is running away before the images are loaded. It
displays the images before they've been fetched (most likely as soon as the
width info can be determined, correct?).
Surely there's a simple way to make it wait until the image is loaded...of
course there is...it was working fine earlier this evening. What may I have
done to break this? What would you suggest to fix it? What's the *right* way
to load a series of images synchronously and force it to wait until they're
loaded before drawing?
Any answers in my mailbox will be much appreciated.
Here are the methods in question:
public synchronized boolean imageUpdate(Image img, int infoFlags,
int x, int y,
int width, int height) {
if ((infoFlags & ERROR) != 0) {
imageLoadError = true;
}
notifyAll();
return true;
}
synchronized Dimension getImageDimensions(Image im)
throws ImageNotFoundException {
// Get the width of the image.
int width;
int height;
dbg("in getImageDimensions");
while ((width = im.getWidth(this)) < 0) {
try {
dbg("in the width wait loop"+width);
wait();
} catch (InterruptedException e) { }
if (imageLoadError) {
throw new ImageNotFoundException(im.getSource());
}
}
// Get the height of the image.
while ((height = im.getHeight(this)) < 0) {
try {
dbg("in the height wait loop");
wait();
} catch (InterruptedException e) { }
if (imageLoadError) {
throw new ImageNotFoundException(im.getSource());
}
}
return new Dimension(width, height);
}
/* and part of my run() */
public void run() {
Dimension dim = null;
Thread me = Thread.currentThread();
dbg("Looks like run() started up alright");
if (!loaded) {
try {
tellLoadingMsg(backgroundImageURL, imageLabel);
dbg("backgroundImageURL ="+backgroundImageURL);
backgroundImage = getImage(backgroundImageURL);
try {
getImageDimensions(backgroundImage);
prefetch(backgroundImage);
repaint();
} catch (Exception e) {
loadError(backgroundImageURL, "background image");
}
}
URL badURL = fetchImages(images);
if (badURL != null) {
loadError(badURL, imageLabel);
return;
}
}
}
}
}
kicker = null;
}
ian
--
ian c rogers http://www.filmzone.com/
Big Gun Project http://www.crashsite.com/Crash/
irogers@biggun.com http://www.nando.net/music/gm/
----- End Included Message -----
-
This message was sent to the java-interest mailing list
Info: send 'help' to java-interest-request@java.sun.com