• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 294
  • Last Modified:

Trouble with displaying multiple images in web applet

I've been stuck on a problem for days now and just can't seem to find the solution to my problem. I'm sure it's something simple I'm overlooking. If anyone can point me in the right direction here I would be most appreciative.

background:

I have a web based java applet that displays two windows of very small images. One window contains 48 images averaging 15x15 while the second window contains something a bit over 100 images ranging up to 110x50 -- The image sources are all defined in an SQL database on the server side and fed into the applet after startup via a tcp/ip socket.

in a nutshell:

If I slow down the loading of the images to about 1 per second or two, then I can load all of the images and display them without a problem. However, if I remove that speed restriction and let the applet rip, the first 20 or so will load almost instantly and then they start "popping in" in somewhat random intervals. About half of the images will, simply, never load no matter how long you wait.

anlaysis:

I am assuming the problem is related to too many threads or sockets running. However, there are no exceptions being thrown and no "problems" I can identify in the Image instance or getImage() call itself -- that is: getImage() is returning a non-null Image instance and it appears to be fine except that it will not paint.

question:

Is anyone familiar with this probelm? If so: how can I detect the problem has occured (programmatically -- it's pretty obvious visually ~smile~) in order to refetch the image or, better still, prevent the problem in the first place without having to wait two or three seconds for every image to load before loading the next one?

public class fubar extends Panel implements ImageObserver
{
    Image image;

    // constructor blah blah blah

    public void paint( Graphics g )
    {
        // this call will never draw anything on the "broken" images
        g.drawImage( image, 0, 0, this );
    }

    public imageUpdate( Image img, int flags, int x, int, y, inw w, int h )
    {
        // this code is never called for about half the images
        System.err.println( "we're in the update func" );
    }
}
0
spiel2001
Asked:
spiel2001
  • 3
  • 3
1 Solution
 
objectsCommented:
how are you loading the images?
do you use MediaTracker to wait for the images to complete loading?
0
 
spiel2001Author Commented:
The images are loaded via

Toolkit.getDefaultToolkit().getImage( new URL( uri ) );

As for MediaTracker -- no. I was not using it (unaware of it) and am looking at that now. Thank you for the tip.

However, let me add something new I've learned by way of trial and error this evening -- I can call getImage() for all 150+ images at once (without a time delay for both image windows combined) and every image will display just fine providing I wait 2-3 seconds between calls to g.drawImage() for each.

Is the Image() not actually fetched until I call g.drawImage()? or is there something else going on here?

In any case, again, thanks for the heads up on MediaTracker -- I'm looking to see how that does for me now.
0
 
objectsCommented:
> Is the Image() not actually fetched until I call g.drawImage()?

Yes, from memory it is not actually fetched until prepareImage() is called. drawImage() would trigger this.
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
spiel2001Author Commented:
That's pretty much the conlusion I had drawn -- looks the the MediaTracker is going to do the trick -- now I've just gotta work out the details on using that class.

Thanks much.
0
 
spiel2001Author Commented:
Ugh -- still learning my way around this... just wanted to give credit where it was due. Thank you again.
0
 
objectsCommented:
No worries :-)
0

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now