我正在尝试制作一个游戏,并且正在使用我找到的图 block 集(png)。我希望能够将图像分解为多个部分并将它们放置在 jframe 中的特定位置以显示运动。但首先我将如何开始导入图像。我所做的所有尝试都失败了,导入时图像变成文本文件。请帮忙解决这个问题,我该如何切割和排列瓷砖?
Exception in thread "main" java.lang.IllegalArgumentException: input == null!
at javax.imageio.ImageIO.read(Unknown Source)
at World.Display.<init>(Display.java:15)
at Main
.main(Main.java:15)
import java.io.IOException;
public class Main {
public static void main(String[] args) throws IOException {
World.Display l = new World.Display();
}
}
package World;
import java.awt.GridLayout;
import java.awt.image.BufferedImage;
import java.io.IOException;
import javax.imageio.ImageIO;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
public class Display {
public Display() throws IOException{
BufferedImage img=ImageIO.read(getClass().getResource("assets/tilesetbackground.png/"));
ImageIcon icon=new ImageIcon(img);
JFrame frame=new JFrame();
frame.setTitle("Another RPG Version: "+Config.Global.Version);
frame.setLayout(new GridLayout(1024,768));
frame.setSize(1024,768);
JLabel lbl=new JLabel();
lbl.setIcon(icon);
frame.add(lbl);
frame.setVisible(true);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}
最佳答案
关于java - 我的应用程序(Java)做错了什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35659511/