Skip to content
Advertisement

JFrame ending in some time

Whenever I run my code it ends in a few seconds. Why?

This is the Main file:

JavaScript

This is the GameWin file:

JavaScript

When I try to run this code it shows running and then the code ends with exit code 1 which is good, but it just ends without showing the window. Is there something wrong with my JRE or JDK?

Advertisement

Answer

  1. Constructors do not have return type. public void GameWin() is not a constructor, thus the default constructor is called that does nothing interesting here. It should be declared public GameWin().

  2. You must call any Swing-related function in the Swing-main-thread for consistency. Thus call the construction of the GameWin object through SwingUtilities class. Even if it seems to work without such, it may not in different kind of environnements.

Hence:

JavaScript
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement