媒体跟踪 - 如何使用它,有什么好处,或者是有一个变质? [英] MediaTracker - how to use it, what are the benefits, or is there an alterative?

查看:217
本文介绍了媒体跟踪 - 如何使用它,有什么好处,或者是有一个变质?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在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的),这强烈暗示的方法由<一个拿href=\"http://download.oracle.com/javase/1.4.2/docs/api/java/awt/MediaTracker.html#MediaTracker%28java.awt.Component%29\"相对=nofollow>构造文档。

So I have 2 questions:

所以,我有2个问题:


  1. 如何以及为什么使用媒体跟踪?

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,它会在后台下载图像,跟踪,当他们做了,甚至给予通知时图像均<一个href=\"http://download.oracle.com/javase/1.5.0/docs/api/java/awt/image/ImageObserver.html#imageUpdate%28java.awt.Image,%20int,%20int,%20int,%20int,%20int%29\">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.

这几天你通常可以载入图像同步,并且最好是用<一个href=\"http://download.oracle.com/javase/1.4.2/docs/api/javax/imageio/ImageIO.html#read%28java.net.URL%29\">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.

这篇关于媒体跟踪 - 如何使用它,有什么好处,或者是有一个变质?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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