如何在屏幕上放置 2 个目录的图像?这是我的代码:
package mousemaze;
// Imports
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JPanel;
public class LoadScreen extends JPanel {
private static final long serialVersionUID = 1L;
private String logoPath = "././images/snakyboLogo.png";
BufferedImage logoImage;
JLabel logoLabel;
public LoadScreen() {
try {
System.out.println(logoPath);
logoImage = ImageIO.read(new File(logoPath));
System.out.println("1");
logoLabel = new JLabel(new ImageIcon(logoImage));
System.out.println("2");
add(logoLabel);
System.out.println("End");
} catch (IOException ex) {
System.out.println("Fail");
}
}
}
但它失败了
logoImage = ImageIO.read(new File(logoPath));
所以我认为它在该目录中找不到指定的文件。我的文件夹结构是:
- src\mousemaze\LoadScreen.java
- src\images\snakyboLogo.png
所以我猜这不是我在完全不同的包中指定文件的方式,那么我该怎么做呢?