I'm just finishing up a Java intro course, and working on my final project. My app is a Java implementation of Yahtzee, and I'm calling it Jahtzee. All I've got so far is some of the initial gui screens created and laid out, and I'm already having a problem I just can't seem to get past. I've spent the last couple hours googling it, but found no solution.
For the purposes of this post, I've cleaned out most of the unrelated code, and just left a skeleton that still displays the issue.
I create a frame, with a panel in it containing a "Quit" button. I want the app to display the frame, and wait for the quit button to be pressed, and then quit. I've obviously not done something right, as the app doesn't wait for the Quit button before continuing on. There is a commented "Thread.sleep(10000);" line in there, and if I uncomment it, then the quit button shows up, and functions correctly, as long as I press it before the 10 seconds have elapsed.
I welcome any comments on what my problem could be, as well as suggestions for improving the logical layout of the app.
When calling setVisible(true) on a frame this will not block, and immediately return. Usually this doesn't matter, because the Event Dispatcher Thread (EDT) will still be active. Only when this thread (and all other non-daemon threads) have ended will the JVM end. However, you call System.exit(0), and this will immediately close the JVM. Remove this one line and your program will show its frame.