My program will not close the specified frame in some cases. For some reason it will close fine when ran through IntelliJ using the run command, but after compiling into a jar and wrapping with Launch4J it gets stuck when I try to close it programmatically. Here is the applicable code:
Classic.java
import javax.swing.*;
import java.io.FileNotFoundException;
import java.io.PrintStream;
import java.util.*;
import java.text.SimpleDateFormat;
import static javax.swing.SwingUtilities.invokeLater;
public class Classic extends Game{
private static JFrame gui;
...
//Starts game and opens gui
public void play() {
invokeLater(Classic::startGUI);
//startGUI() intiates gui correctly, let me know if you need it
new Thread(Classic::startGame).start();
}
...
public static void startGame() {
//Program works fine until closing window;
//Game methods and code omitted
print("Thank you for playing!" + System.lineSeparator() + "Press enter to exit.");
boolean end = false;
while (!end) {
//isInputReady() checks if user pressed enter
end = newContentPane.isInputReady();
}
gui.dispose();
}
}
I'm not sure if this is a code error or an error with Launch4J since this only occurs in the Launch4J compiled version (not through IntelliJ or via java.exe -jar).
EDIT: I also tried killing the GUI thread with thread.interrupt(), but that didn't change the outcome.