Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (476)
Games in Android Showcase (106)
games submitted by our members
Games in WIP (532)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Jar and JFrame problems  (Read 1093 times)
0 Members and 1 Guest are viewing this topic.
Offline FoolishFate

Junior Newbie




Java games rock!


« Posted 2005-02-13 13:01:49 »

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.  Huh 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
Offline 20thCenturyBoy

Senior Member


Medals: 3


So much to learn, so little time.


« Reply #1 - Posted 2005-02-13 13:10:12 »

Does it dump an exception stack trace when it closes?

"I have never done unit testing and I don’t find it a very useful concept" - Jonathan Blow
Offline K.I.L.E.R

Senior Member




Java games rock!


« Reply #2 - Posted 2005-02-13 13:21:15 »

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.

Vorax:
Is there a name for a "redneck" programmer?

Jeff:
Unemployed. Wink
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline FoolishFate

Junior Newbie




Java games rock!


« Reply #3 - Posted 2005-02-13 13:37:40 »

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?
Offline CaptainJester

JGO Knight


Medals: 12
Projects: 2
Exp: 14 years


Make it work; make it better.


« Reply #4 - Posted 2005-02-14 02:11:25 »

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:

1  
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.

Offline FoolishFate

Junior Newbie




Java games rock!


« Reply #5 - Posted 2005-02-14 17:18:00 »

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
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

pw (17 views)
2014-07-24 01:59:36

Riven (17 views)
2014-07-23 21:16:32

Riven (14 views)
2014-07-23 21:07:15

Riven (17 views)
2014-07-23 20:56:16

ctomni231 (45 views)
2014-07-18 06:55:21

Zero Volt (40 views)
2014-07-17 23:47:54

danieldean (32 views)
2014-07-17 23:41:23

MustardPeter (36 views)
2014-07-16 23:30:00

Cero (51 views)
2014-07-16 00:42:17

Riven (50 views)
2014-07-14 18:02:53
HotSpot Options
by dleskov
2014-07-08 03:59:08

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:58:24

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:47:22

How do I start Java Game Development?
by ra4king
2014-05-17 11:13:37

HotSpot Options
by Roquen
2014-05-15 09:59:54

HotSpot Options
by Roquen
2014-05-06 15:03:10

Escape Analysis
by Roquen
2014-04-29 22:16:43

Experimental Toys
by Roquen
2014-04-28 13:24:22
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!