1

I have a game developed in Eclipse, and it works great when I run it from there. It gives you a JFrame frame, where you can select difficulty and if you done it, you can play with the game, in a new frame. It worked well, until I created the setup frame.

So in Eclipse, i run the app, i set the setup, click the button, the first frame goes invisible, and this opens the next frame. When executing the exported runnable jar, it doesn't stop, but the second frame (the game frame) is invisible.

Here's the main.

public static void main(String[] args) {
    int ammuData = 0;
    int enemyData = 0;
    Config config = new Config();

    while (config.frame.isVisible()) {
        ammuData = config.getAmmu();
        enemyData = config.getEnemies();
    }

    Game game = new Game(ammuData, enemyData);
    game.frame.setResizable(false);
    game.frame.setTitle(Game.title);
    game.frame.add(game);
    game.frame.pack();
    game.frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    game.frame.setLocationRelativeTo(null);
    game.frame.setVisible(true);
    game.start();
}
Doctor Jones
  • 21,196
  • 13
  • 77
  • 99
kkrisz999
  • 23
  • 3
  • 1
    Have you tried debugging the application running outside of Eclipse? http://java.dzone.com/articles/how-debug-remote-java-applicat – MaQy Nov 27 '13 at 08:58
  • could you post code of Game and Config? – Blub Nov 27 '13 at 08:58
  • I think that you while condition doesn't stop (goes into infinite loop), so it will not reach you game.setVisible(true); – Salah Nov 27 '13 at 09:00
  • if on Windows, you may try to use Process Explorer, to see precisely the java(w) command line parameters with which Eclipse launches the application and then compare it to the command line parameters used when you launch it manually. – John Donn Nov 27 '13 at 09:13
  • You should not use polling loops like this. It will create 100% CPU load on one core for doing nothing useful. Either use a modal `Dialog` whose `setVisible(true)` method will return when the dialog is closed or use a `WindowListener` to get notified when the frame has been closed. – Holger Nov 27 '13 at 09:59
  • 1) See [The Use of Multiple JFrames, Good/Bad Practice?](http://stackoverflow.com/a/9554657/418556) 2) For many components in one space, use a [`CardLayout`](http://docs.oracle.com/javase/7/docs/api/java/awt/CardLayout.html) as seen in this [short example](http://stackoverflow.com/a/5786005/418556). – Andrew Thompson Nov 27 '13 at 13:35
  • My game works on several other PCs. I reainstalled my JVM. Still nothing. – kkrisz999 Nov 28 '13 at 22:44

0 Answers0