If the loading of images on a network, a common problem faced by Java applets are not loading images properly. In a fast network connection, the picture will download quickly, but with a slow modem or network connection, take pictures more time, or can not reach. Users can be confused by the pictures do – especially when a sequence of images shown. An easy way to your users know that the load MediaTracker to recognize enables the applets, when images are loaded to use.
Ask any user who connects via a modem dial-up, what they think applets, and the answer is often that they are loaded slowly. As one user said, I do not like ugly gray box applet found there on the page. Very often an applet images from a kind of animation is loaded – but you do not know what happened. Other times, do not sit properly loaded applets there with a box of gray-white. This adds to the confusion, as a float applet often means broken.
When you write applets, we have the developer the responsibility of users, so they know what is happening. When the applet loads images via a network connection, it is important to monitor your progress, and inform the user.
Here he comes in MediaTracker MediaTracker allows applets to determine whether an image is loaded or not. Applets can be loaded images with a MediaTracker object and for any or all images to wait. Although the images are loaded, a message can be displayed to the user. If all images are loaded, then the applet can be processed – for example, appears as part of an animation. Note, however, can benefit MediaTracker applications and applets – even when loading a local file system, it can be loaded to significant delays at many large images.
/ / Import the AWT graphics package import java.awt .*, then you have an instance java.awt.MediaTracker. Must pass an instance of java.awt.Component MediaTracker constructor. An applet is a subclass of the component so that when writing an applet on a Web page, the applet can use this keyword will be accepted.
/ / Load a MediaTracker instance to / / image tracker = new MediaTracker monitor walls (this) Once you have a media tracker, you can simply upload any image and save it using the MediaTracker.addImage (Image, int). The first parameter is included as an image and IDCode image as the second parameter. The IDCode can be used to inquire about the status of a particular image, rather than a group of images.
/ / Register trackertracker.addImage with the media (img, 1) Once you have saved the image, you can receive a text message or a simple animation, so users know that the data is loaded. Of course, you also need to consider whether the pictures are ready for use by consulting media tracker.
There are two ways to check the status of the images. The first is a continuous survey of MediaTracker MediaTracker.checkID (int).
> Else </ / show the animation> Another way, and often the easiest is to wait indefinitely until all images are loaded. Note that it can be best provided in a separate thread of execution if the applet can still respond to user events and display a message. This is a blocking operation during which MediaTracker.checkID (int) non-blocking and returns immediately is.
/ / Wait until all images have loadedtracker.waitForAll ();

