使用MediaTracker在Swing应用程序中缓存图像 [英] Using MediaTracker to cache images in Swing Application

查看:399
本文介绍了使用MediaTracker在Swing应用程序中缓存图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个基于Swing的金融股票代码,它会显示价格变动的金融符号以及每个柜台/公司的向上或向下箭头。

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.

这个自动收报机在计数器上可以有很多(最多100个),并且需要缓存图像符号以提高性能。

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

我试过这个文章但未能理解,尤其是MediaTracker类将如何缓存图像。从我所看到的,我将图像放在一个数组中,仍然从数组中检索。

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?

推荐答案

MediaTracker将帮助您跟踪加载大量图像,但就是这样。一旦加载了所有内容,您将需要类似于旧的地图,其中的图像与文件名或公司名称或ID进行对比。

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>();

使用MediaTracker在1.4 JavaDocs上加载图像有一个合理的例子: http://java.sun.com/j2se/1.4.2 /docs/api/java/awt/MediaTracker.html 。请注意,没有getImage()方法,您需要一个int id才能跟踪它们。你必须自己维护BufferedImage引用,因此HashMap<>。

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<>.

这篇关于使用MediaTracker在Swing应用程序中缓存图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆