Hi !
Featured games (90)
games approved by the League of Dukes
Games in Showcase (789)
Games in Android Showcase (234)
games submitted by our members
Games in WIP (864)
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 2155 times)
0 Members and 1 Guest are viewing this topic.
Offline FoolishFate

Junior Newbie

Java games rock!

« Posted 2005-02-13 12: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.

Offline 20thCenturyBoy

Senior Devvie

Medals: 3

So much to learn, so little time.

« Reply #1 - Posted 2005-02-13 12: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 Devvie

Java games rock!

« Reply #2 - Posted 2005-02-13 12: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.

Is there a name for a "redneck" programmer?

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

     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));
           ventana.setBounds(0, 0, Stage.WIDTH, Stage.HEIGHT);
           strategy = getBufferStrategy();

           BufferedImage cursor = spriteCache.createCompatible(10, 10,
           Toolkit t = Toolkit.getDefaultToolkit();
           Cursor c = t.createCustomCursor(cursor, new Point(5, 5), "null");
public void game() {
           // INITIALISE GAME //
                 while (isVisible()) {
           long startTime = System.currentTimeMillis();
           usedTime = System.currentTimeMillis() - startTime;
           do {
           } 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 01: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:

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 16: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  :-/

Pages: [1]
  ignore  |  Print  

hadezbladez (2617 views)
2018-11-16 13:46:03

hadezbladez (944 views)
2018-11-16 13:41:33

hadezbladez (2571 views)
2018-11-16 13:35:35

hadezbladez (509 views)
2018-11-16 13:32:03

EgonOlsen (3738 views)
2018-06-10 19:43:48

EgonOlsen (4136 views)
2018-06-10 19:43:44

EgonOlsen (2496 views)
2018-06-10 19:43:20

DesertCoockie (3303 views)
2018-05-13 18:23:11

nelsongames (3399 views)
2018-04-24 18:15:36

nelsongames (4376 views)
2018-04-24 18:14:32
Java Gaming Resources
by philfrei
2019-05-14 16:15:13

Deployment and Packaging
by philfrei
2019-05-08 15:15:36

Deployment and Packaging
by philfrei
2019-05-08 15:13:34

Deployment and Packaging
by philfrei
2019-02-17 20:25:53

Deployment and Packaging
by mudlee
2018-08-22 18:09:50

Java Gaming Resources
by gouessej
2018-08-22 08:19:41

Deployment and Packaging
by gouessej
2018-08-22 08:04:08

Deployment and Packaging
by gouessej
2018-08-22 08:03:45 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‑
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!