1

Let me know if you need more code than this!

I can run the program perfectly fine in Eclipse. But once I access the files and run java Frame in Terminal, it only shows part of my game. It doesn't show any of the .png files.

Here is my main method:

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();


}

}

And here is how I am accessing the files in Eclipse, which doesn't seem to work in Terminal:

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)));
    }
Rashesh
  • 15
  • 3

1 Answers1

0

It seems the problem is that on the Terminal, the program is being run from the Client/src folder and thus it tries to look for the images on Client/src/res, which does not exist.

Eclipse on the other hand, keeps separate folders and launches the program using the project folder as its root folder:

Client
|
+-- bin (classes compiled by Eclipse)
|
+-- res (images)
|
+-- src (source code)

By running javac *.java while on the src folder you're creating a copy of the compiled classes on the src folder.

On the Terminal you need to return to the Client folder and launch your program from there with java -classpath bin Frame

Denis Fuenzalida
  • 3,271
  • 1
  • 17
  • 22
  • THANK YOU! It worked! Thank you so much. Now is there anyway I can make a Driver class that does that code for me? I want to just be able to go to the Client folder and type "java Driver" and have it run that code. – Rashesh Mar 18 '13 at 02:47
  • To do that you'll need to create a launcher script for running your program from the command line, see this link: http://stackoverflow.com/a/9660103/483566 – Denis Fuenzalida Mar 18 '13 at 03:11
  • Is there a way for me to move around the files so I can just use "java Frame" and have it work? – Rashesh Mar 18 '13 at 04:28
  • You would have to copy the compiled classes to the Client folder, so that the current folder contains the file Frame.class and the "res" folder (which is already on the right place) – Denis Fuenzalida Mar 18 '13 at 13:22
  • Awesome. It works! Thank you so much. I don't know why that was stumping me for so long. Thanks again! – Rashesh Mar 18 '13 at 14:01