繁体   English   中英

Eclipse Java应用程序找不到资源

[英]Eclipse Java application can't find resources

我有一个正在制作的应用程序的启动屏幕。 这是一个带有JPanelJLabelJWindow ,然后在JLabel上有一个ImageIcon 使用this.getClass.getResourceAsStream("GenericApp.png");InputStream加载ImageIcon this.getClass.getResourceAsStream("GenericApp.png"); 我的初始屏幕代码如下:

final JWindow window = new JWindow();
JPanel jp = new JPanel();
InputStream is = this.getClass().getResourceAsStream("GenericApp.png");
Image image = null;
try {
    image = ImageIO.read(is);
} catch (IOException e1) {
    // TODO Auto-generated catch block
    e1.printStackTrace();
}
JLabel l = new JLabel(new ImageIcon(image));
window.add(jp);
jp.add(l);
window.setBounds(500, 150, 300, 200);
window.setVisible(true);
try{
    Thread.sleep(5000);
}catch(InterruptedException e){
    e.printStackTrace();
}
window.setVisible(false);

启动项目时,我得到一个空白的JWindow,它具有设置的尺寸。

这是我解决的方法:

显然,该图像需要一段时间才能加载。 在完成加载图像并因此中断显示过程之前,我正在调用Thread.sleep(5000) 这个故事的寓意是,您几乎永远不想使用Thread.sleep() USE TIMERS INSTEAD

问候,

托马斯

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM