views:

349

answers:

1

I have a Swing based financial ticker, that will display a financial symbol the price movement and an arrow for either up or down for each counter / company.

This ticker can have a lot on counters (up to 100), and see the need to cache the images symbols to boost performance.

I have tried following this article but fail to understand it, especially how the MediaTracker class is going to cache the images. From what i can see, i place the images in an array and still retrieve from the array.

Does anyone know how it works and is supposed to be used?

+1  A: 

A MediaTracker will help you keep a track on loading lots of images, but that's about it. Once all is loaded you'll be need something like a good old Map with the images hashed against either the filename or the company name or ID.

private Map<String,Image> imageCache = new HashMap<String,Image>();

There's a reasonable example of using a MediaTracker to load images on the 1.4 JavaDocs: http://java.sun.com/j2se/1.4.2/docs/api/java/awt/MediaTracker.html. Note that there's no getImage() method, and you need an int id in order to track them. You have to maintain the BufferedImage references yourself, hence the HashMap<>.

banjollity