在Java中异步加载基于网络的图像
我必须能够加载和绘制位于基于网络的驱动器上的 X 数量的图像。 我需要帮助找到异步加载图像的方法。
java.net.URL Loc = new URL("http://auroragm.sourceforge.net/GameCover/GameCases/Mass-Effect.png");
JLabel lbl = new JLabel();
lbl.setIcon((anotherIcon = new ImageIcon(Loc)));
上面是在 GUI 线程上加载的一张图像,因此如果要加载另外 20 个图像,就会冻结。任何帮助将不胜感激
I have to be able to load and draw X amount of images located on a network based drive.
I need help finding a way to load the images asynchronously.
java.net.URL Loc = new URL("http://auroragm.sourceforge.net/GameCover/GameCases/Mass-Effect.png");
JLabel lbl = new JLabel();
lbl.setIcon((anotherIcon = new ImageIcon(Loc)));
The above is one image which loads on the GUI thread and thus would freeze if 20 more were to be loaded. Any help would be appreciated
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在单独的线程中加载图像。请将以下代码视为伪代码:
Load the images in separate thread. Please treat below code as pseudo-code:
简短的回答:您应该在另一个线程上加载图像。
Swing 确实提供了一组很好的类和类。模式:
http://download.oracle.com /javase/6/docs/api/javax/swing/SwingWorker.html
Short answer: you should load the images on another thread.
Swing does provide a nice set of classes & patterns for this:
http://download.oracle.com/javase/6/docs/api/javax/swing/SwingWorker.html