问题描述
在codeBase的我们继承的总是在本地各code座完成。
In the codebase we inherited the usage of MediaTracker was always done locally in each code block.
new MediaTracker(new Canvas());
mediatracker.addImage(i, 1);
try {
mediatracker.waitForAll();
} catch (InterruptedException e) { }
mediatracker.removeImage(i);
决定,这是低效的,我最终与静态实例和方法取代了它
final static protected MediaTracker mediatracker = new MediaTracker(new Canvas());static protected void checkImageIsReady(Image i) { mediatracker.addImage(i, 1); try { mediatracker.waitForAll(); } catch (InterruptedException e) { } mediatracker.removeImage(i);}
Thus far there have been no ill effects.
到目前为止没有出现过不良影响。
There is another possible approach - to attach the MediaTracker to each component (usually a Frame or JFrame) which is strongly implied as the approach to take by the constructor documentation.
有另一种可能的方法 - 给媒体跟踪器连接到每个组件(通常是一个Frame或JFrame的),这强烈暗示的方法由构造文档。
So I have 2 questions:
所以,我有2个问题:
-
如何以及为什么使用媒体跟踪?
What is the alternative?
什么是另类?
推荐答案
媒体跟踪是在1995年用当时的主要GUI使用java小程序是,和小程序通常会在网络上慢慢地加载图像。
MediaTracker was useful in 1995. Back then the primary GUI use of java was Applets, and Applets would usually load images slowly over the network.
要使它更容易为Applet的作家,JAVA给了我们一个很好的媒体跟踪API,它会在后台下载图像,跟踪,当他们做了,甚至给予通知时图像均partially加载。该媒体跟踪API意味着小程序编写者没有阻止应用程序,同时图像慢慢下载,并没有写复杂的线程code在后台线程加载图像。
To make it easier for Applet writers, java gave us a nice MediaTracker api which would download images in the background, tracking when they were done, and even give notifications when images were partially loaded. The MediaTracker API meant Applet writers didn't have to block the application while images slowly downloaded, and didn't have to write complicated threading code to load images in background threads.
这几天你通常可以载入图像同步,并且最好是用ImageIO.这对于图像从本地文件系统加载的常见的情况,尤其如此。
These days you can typically load images synchronously, and it is best to use ImageIO. This is especially true for the common case where images are loaded from the local file system.
这篇关于媒体跟踪 - 如何使用它,有什么好处,或者是有一个变质?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!