This topic is 4267 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

I've looked everywhere I can't seem to find any tutorials on making a loading bar in Java to show how much of the media has been loaded etc. Could anyone point me in the right direction? I'm sure it has something to do with MediaTrackers but whenever I've tried something it's failed.

Share on other sites
Is there a way without using Swing?

Share on other sites
A progress bar is basically just a rectangle which is gradually filled so

DrawRectangle(0, top, (width * progress) / maxProgress, height, color);

should do the trick. This is, as you can see, not java specific. You said you didn't want swing so I guess you're drawing the gui parts yourself?

Share on other sites
Yes. I know how to draw the rectangle that's fine. It's just how to tell whether an image has loaded and increasing it without the whole Applet freezing that's the trouble. I wanted to get a more personal feel with my GUI so I am writing those parts myself. An example of the sort of thing I would like is like the one in RuneScape (Which I happen to be playing at the time :P)

Share on other sites
I think he updates based on each image loaded, not on how much of an image is loaded.

If that is what you want, then just use MediaTracker and a separate id for each image.

MediaTracker mt = new MediaTracker(this);for(int i=0;i<numImages;i++) {  image = getImage("somfile.jpg");  mt.addImage(image, i);}for(int i=0;i<numImages;i++) {  while(!mt.checkID(i)) {    try {      //required to keep this thread from locking others      Thread.sleep(20);    }    catch(InterruptedException e) {}  }  //updateProgress here}

If you want to use ImageIO instead of the old way:
for(int i=0;i<numImages;i++) {  image = ImageIO.read("somefile");  //updateProgress here}

Since ImageIO blocks until the image is loaded, you don't need MediaTracker.

Share on other sites
Thank you. I will incorporate this into my Sprite class. I've never used ImageIO before it seems to be a lot simpler...

Share on other sites
Quote:
 Original post by Dom_152Thank you. I will incorporate this into my Sprite class.

On your Sprite class?!? Don't you think this responsibility belongs to another class? (i.e a GameState? =)

• 10
• 17
• 9
• 13
• 41