我有一个问题,当我创建一个可运行的 jar 文件时,屏幕上没有加载任何内容。经过一些研究,我认为问题与我如何加载图像有关,但我不确定解决该问题的解决方案。
下面的代码只是我如何加载图像的一个片段。
谢谢~
public class Screen extends JPanel implements Runnable {
public Thread thread = new Thread(this);
public static Image[] tileset_ground = new Image[100];
public static Image[] tileset_air = new Image[100];
public static Image[] tileset_res = new Image[100];
public static Image[] tileset_mob = new Image[100];
public static Image[] tileset_characters = new Image[10];
public static int myWidth, myHeight;
public static int coinage, health;
public static int randomMob = 0;
public static int level = 1, maxLevel = 5;
public static int killed = 0;
public static int killsToWin = 0;
public static int winTime = 4000, winFrame = 0;
public int mobsCreated = 0;
public static boolean isFirst = true;
public static boolean isDebug = false;
public static boolean isWin = false;
public static boolean isMainMenu = true;
public static boolean exit = false;
public static boolean clicked = false;
public static Point mse = new Point(0,0);
public static Room room;
public static Save save;
public static Store store;
public static MainMenu mainMenu;
public static Mob[] mobs = new Mob[100];
public Screen(Frame frame) {
frame.addMouseListener(new KeyHandle());
frame.addMouseMotionListener(new KeyHandle());
thread.start();
}
public void hasWon(){
if(killsToWin == killed){
isWin = true;
killed = 0;
coinage = 10;
}
}
public void define() {
room = new Room();
save = new Save();
store = new Store();
coinage = Values.coinage;
health = Values.health;
for(int i =0; i<tileset_ground.length; i++) {
tileset_ground[i] = new ImageIcon("res/tileset_ground.png").getImage();
tileset_ground[i] = createImage(new FilteredImageSource(tileset_ground[i].getSource(), new CropImageFilter(0,26*i,26,26)));
}
for(int i =0; i<tileset_air.length; i++) {
tileset_air[i] = new ImageIcon("res/tileset_air.png").getImage();
tileset_air[i] = createImage(new FilteredImageSource(tileset_air[i].getSource(), new CropImageFilter(0,26*i,26,26)));
}
tileset_res[0] = new ImageIcon("res/cell.png").getImage();
tileset_res[1] = new ImageIcon("res/coin.png").getImage();
tileset_res[2] = new ImageIcon("res/heart.png").getImage();
tileset_res[3] = new ImageIcon("res/startbutton.png").getImage();
tileset_res[4] = new ImageIcon("res/quitbutton.png").getImage();
tileset_res[5] = new ImageIcon("res/cellchar.png").getImage();
tileset_res[6] = new ImageIcon("res/mainmenu.png").getImage();
tileset_mob[0] = new ImageIcon("res/pixelcody.png").getImage();
tileset_mob[1] = new ImageIcon("res/floatingmob1.png").getImage();
tileset_mob[10] = new ImageIcon("res/pixelraghev.png").getImage();
tileset_characters[1] = new ImageIcon("res/pixelcody.png").getImage();
tileset_characters[2] = new ImageIcon("res/pixelraghev.png").getImage();
tileset_characters[4] = new ImageIcon("res/pixelbio.png").getImage();
tileset_characters[3] = new ImageIcon("res/pixelpeter.png").getImage();
tileset_characters[5] = new ImageIcon("res/pixelkat.png").getImage();
tileset_characters[7] = new ImageIcon("res/pixelvicky.png").getImage();
tileset_characters[6] = new ImageIcon("res/pixelkyle.png").getImage();