?
Solved

Trouble with displaying multiple images in web applet

Posted on 2003-02-26
6
Medium Priority
?
275 Views
Last Modified: 2010-03-31
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
Comment
Question by:spiel2001
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
6 Comments
 
LVL 92

Expert Comment

by:objects
ID: 8031802
how are you loading the images?
do you use MediaTracker to wait for the images to complete loading?
0
 
LVL 1

Author Comment

by:spiel2001
ID: 8031856
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
 
LVL 92

Accepted Solution

by:
objects earned 200 total points
ID: 8031912
> 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 1

Author Comment

by:spiel2001
ID: 8032077
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
 
LVL 1

Author Comment

by:spiel2001
ID: 8032080
Ugh -- still learning my way around this... just wanted to give credit where it was due. Thank you again.
0
 
LVL 92

Expert Comment

by:objects
ID: 8036956
No worries :-)
0

Featured Post

Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
In this post we will learn different types of Android Layout and some basics of an Android App.
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.
Suggested Courses
Course of the Month13 days, 16 hours left to enroll

800 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question