Presentation is loading. Please wait.

Presentation is loading. Please wait.

Preloading Images for better Performance Using the MediaTracker class.

Similar presentations


Presentation on theme: "Preloading Images for better Performance Using the MediaTracker class."— Presentation transcript:

1 Preloading Images for better Performance Using the MediaTracker class

2 Introduction If your applet uses a lot of images, all of them may not be able to load fast enough As a result you might get half-images If you use the MediaTracker class to preload all your images you can avoid this problem

3 In the variable section MediaTracker tracker; Image pic,pic2; declare a MediaTracker object Declare all the images you are going to use Dont for get to put them in the same directory as your.class file

4 In the init() method Besides all the other initializations you need for you program you should call a separate method you will make to do the image initializations eg: –initImages();

5 In the initImages() method public void initImages() { tracker=new MediaTracker(this); pic=getImage(getCodeBase(),"spaceship.gif"); tracker.addImage(pic,0); pic2=getImage(getCodeBase(),"spaceship2.gif"); tracker.addImage(pic2,1); //load rest of the images in the same way try {tracker.waitForAll();} catch(InterruptedException e) {} } initialize the MediaTracker object load an image as before add the image to the tracker index of the images in the tracker These lines try to catch any errors in loading the images


Download ppt "Preloading Images for better Performance Using the MediaTracker class."

Similar presentations


Ads by Google