Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Displaying loaded images

Status
Not open for further replies.

NiceButDim

Programmer
Feb 12, 2002
154
GB
Hi,
I have an image that I am loading and displaying on my applet. I have a problem in that the image does not appear when the applet is first run. If you refresh the applet (i.e. hide then unhide the window) the image is there. It appears that I have to leave time for the image to fully load before drawing because I have found that after loading, if I add the following code;
while(image.getWidth()==-1);
all is well. Although this solves my problem I would assume that it is not the ‘correct’ way to deal with this ‘problem’.
I would be grateful for any pointers on how I should deal with this issue.
Thanks.
 
Basically you need to force a repaint of the area, which is what is happening when you drag another window over and then drag the original in front. The API has some information on this subject as well as information on double buffering, which may not be necessary, but will show information on overriding the repaint.

-Tarwn ________________________________________________________________________________
Want to get great answers to your Tek-Tips questions? Have a look at faq333-2924
 
Hi,
Thanks for replying.
I don't think however that the problem is to do with repainting (i'm new to Java so I could easily be wrong!).
Below are 2 pieces of code;

public void init() {
hand = getImage(getCodeBase(),"hand.gif");
handWidth = hand.getWidth(this);
}

public void init() {
hand = getImage(getCodeBase(),"hand.gif");
while(hand.getWidth(this)==-1);
handWidth = hand.getWidth(this);
}

If I use the first version of init the value of handWidth is set to -1, in the second version the variable is set to it's correct value. My assumption was that there must be a setting somewhere which indicates that processing should not continue until the image is completely loaded. Further, doing the while loop as I am above doesn't trap error and to do so makes the process of loading & using images more messy than it should be. There must be a simple explanation!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top