如何从java中的其他包导入图标

如何从java中的其他包导入图标,java,import,icons,jlabel,Java,Import,Icons,Jlabel,好的,我使用这段代码从类所在的同一文件中导入一个图标,并为其分配一个JLabel JLabel label1; Icon iron_ore = new ImageIcon(getClass().getResource("icon_ore")); label1 = new JLabel(iron_ore); 但是如果我想把图标放在一个不同于类所在的文件中,我需要添加什么代码呢?谢谢。如果图像在包foo.bar.baz中,您可以使用 getClass().getResource("/foo/bar

好的,我使用这段代码从类所在的同一文件中导入一个图标,并为其分配一个
JLabel

JLabel label1;
Icon iron_ore = new ImageIcon(getClass().getResource("icon_ore"));
label1 = new JLabel(iron_ore);

但是如果我想把图标放在一个不同于类所在的文件中,我需要添加什么代码呢?谢谢。

如果图像在包
foo.bar.baz
中,您可以使用

getClass().getResource("/foo/bar/baz/the-icon.png")

当然,正如javadoc中所解释的。

请更清楚一点。