如果你需要更多的代码,请让我知道!
我可以在Eclipse中很好地运行这个程序。但是,一旦我访问这些文件并在终端中运行java Frame,它只显示了我游戏的一部分。它不显示任何.png文件。
下面是我的主要方法:
import javax.swing.*;
import java.awt.*;
public class Frame extends JFrame {
public static String title = "Tower Defense Alpha";
public static Dimension size = new Dimension(700, 550);
public Frame() {
setTitle(title);
setSize(size);
setResizable(false);
setLocationRelativeTo(null);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
init();
}
public void init(){
setLayout(new GridLayout(1,1,0,0));
Screen screen = new Screen(this);
add(screen);
setVisible(true);
}
public static void main(String args[]){
Frame frame = new Frame();
}}
下面是我在Eclipse中访问文件的方式,这在终端中似乎不起作用:
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)));
}发布于 2013-03-18 10:43:33
问题似乎出在终端上,该程序是从Client/src folder运行的,因此它试图在Client/src/res上查找不存在的图像。
另一方面,Eclipse保留单独的文件夹,并使用项目文件夹作为其根文件夹来启动程序:
Client
|
+-- bin (classes compiled by Eclipse)
|
+-- res (images)
|
+-- src (source code)通过在src文件夹中运行javac *.java,您可以在src文件夹中创建已编译类的副本。
在终端上,您需要返回到Client文件夹并从那里使用java -classpath bin Frame启动您的程序
https://stackoverflow.com/questions/15467520
复制相似问题