Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/image-processing/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Eclipse Java应用程序可以';找不到资源_Java_Swing_Embedded Resource - Fatal编程技术网

Eclipse Java应用程序可以';找不到资源

Eclipse Java应用程序可以';找不到资源,java,swing,embedded-resource,Java,Swing,Embedded Resource,我有一个我正在制作的应用程序的启动屏幕。它是一个JWindow,带有JPanel和JLabel的窗口,然后在JLabel上有一个ImageIcon。使用this.getClass.getResourceAsStream(“GenericApp.png”),ImageIcon从InputStream加载。我的启动屏幕代码如下: final JWindow window = new JWindow(); JPanel jp = new JPanel(); InputStream is = this.

我有一个我正在制作的应用程序的启动屏幕。它是一个
JWindow
,带有
JPanel
JLabel
的窗口,然后在
JLabel
上有一个
ImageIcon
。使用
this.getClass.getResourceAsStream(“GenericApp.png”),
ImageIcon
InputStream
加载。我的启动屏幕代码如下:

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

当我启动我的项目时,我得到一个带有我设置的维度的空白窗口。

以下是我如何解决它的:

显然,加载图像需要一段时间。我正在调用
Thread.sleep(5000)
,它还没加载完图像,就中断了显示过程。这个故事的寓意是,你几乎永远不想使用
线程。sleep()
而是使用计时器

问候,


Thomas

那么,this.getClass()返回的类的包是什么?您把png文件放在哪里了?有例外吗?堆栈跟踪是什么?没有堆栈跟踪,因为IconImage没有给出堆栈跟踪。
this.getClass
的输出是:
class iamthethomas.artint.CreateJFrame
png文件与CreateJFrame在同一个包中。1)不要阻止EDT(事件调度线程)。发生这种情况时,GUI将“冻结”。有关详细信息和修复方法,请参阅。2)
window.setBounds(500150300200)最好是
window.pack();/*根据图像调整窗口大小*/window.setLocation(500150)
@thewrenchinsystem:Don't
sleep()
在EDT上;一定要看和看。