Jar and JFrame problems

Hi, and sorry for this topic.

My program runs fine as an application in Eclipse. But when I try to run the Jar file, the JFrame opens, then closes again, straight away. It doesn’t do this on an earlier version of the game, nor when run in Eclipse, and i cannot see any changes that would cause this to happen. I’m stumped. ??? There’s no code that would cause it to close, apart from setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE)

Any help at all would be appreciated. I know its a pretty vague topic, so if anyone would help, I’ll email the Jar’s, or whatever you need.

Thanks

Does it dump an exception stack trace when it closes?

Are you sure you initialised it right?
When I was new to Swing/AWT I had that problem as well.
It was due to not initialising my window properly.

I don’t remember the solution to the problem but it was in my initialisation.
It would help greatly if you posted your code.

The actual JFrame closes fine, but for the split second it appears, its blank. Could it be a problem with the resources in the Jar file?

public class FrontEnd extends Canvas implements Stage, KeyListener {

public static void main(String[] args) {
FrontEnd front = new FrontEnd();
front.game();
}

  public FrontEnd() {
        // Initialise New Window
        spriteCache = new SpriteCache();
        soundCache = new SoundCache();

        JFrame ventana = new JFrame("RA Invaders");
        JPanel panel = (JPanel) ventana.getContentPane();
        setBounds(0, 0, Stage.WIDTH, Stage.HEIGHT);
        panel.setPreferredSize(new Dimension(Stage.WIDTH, Stage.HEIGHT));
        panel.setLayout(null);
        panel.add(this);
        ventana.setBounds(0, 0, Stage.WIDTH, Stage.HEIGHT);
        ventana.setVisible(true);
        ventana.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        ventana.setResizable(false);
        createBufferStrategy(2);
        strategy = getBufferStrategy();
        requestFocus();

        addKeyListener(this);
        setIgnoreRepaint(true);
        BufferedImage cursor = spriteCache.createCompatible(10, 10,
                    Transparency.BITMASK);
        Toolkit t = Toolkit.getDefaultToolkit();
        Cursor c = t.createCustomCursor(cursor, new Point(5, 5), "null");
        setCursor(c);
        
  }


public void game() {
// INITIALISE GAME //
initGame();
initLevel();

              while (isVisible()) { 
        t++;
        long startTime = System.currentTimeMillis();
        checkForEndOfLevel();
        updateWorld();
        checkCollisions();
        paintWorld();
        usedTime = System.currentTimeMillis() - startTime;
        do {
              Thread.yield();
        } while (System.currentTimeMillis() - startTime < 17);
  }
  }

That’s basically the main part of the code that deals with the JFrame, if you need anything else, I’ll post/email it.
Any ideas?

First, you are mixing Swing with AWT. You should not do that. This would not cause your problem, but can cause other problems.

Your problem could be a ClassCastException on this line:

JPanel panel = (JPanel) ventana.getContentPane();

While JPanel is a Container, there is no guaruntee that a content pane will be a JPanel.

When you are running it, do you double click the JAR, or are you running it from the command line? If you are not going from the command line, you should, because you will see any exceptions that are happening that way.

Ok, I had to modify this post. The main problem was my filenames. I was mis-spelling my image names. The only real problem is with my scrolling background code. I can sort that out easily enough.

Stupid me :-/

Thanks