I have written the following little framework for a game I was hoping to write for Linux. This works fine with the same version of the JDK on Windows - a black screened window with a frames-per-second readout on the top left, but this fails to work under Fedora 10. I have installed Sun's official JDK and all I get is the Swing window which is the default grey and nothing else.

The official Sun JDK is in the system path (/etc/profile) and I have compiled it using that and also uninstalled the OpenJDK stuff but to no avail. What the hell is going on? Any ideas? As I said, this code works perfectly under Windows with the same version of the JDK. I even ran "javac -version" and "java -version" to make sure no other Fedora-specific JDK was overriding the official one. But nothing helps.

Changes to the properties of a visible component must occur on the event dispatch thread. You are creating and changing the properties of your canvas outside of the EDT. As swpalmer points out, if you create your Universe object in the invokelater() method it will be run on the EDT. Google swing and thread safety.

Okay, so I have read and understand the principle, but still don't see how this applies to my program as in the examples I've seen create JFrames and such in the main() method. So would I have to change my Universe object to include the SwingUtilties.invokeLater() method and move my initUniverse() method to there or can I include the SwingUtilities.invokeLater() method in my Game object and create my Universe instance there and if so, how will main() know to call the invokeLater() method and thus start the game?

You can create swing components off of the EDT. You just can't modify them after they've been realized off of the EDT. The way your class is set up right now it realizes the canvas and modifies it in the constructor. If you wish to keep this functionality then you must create your class on the EDT with invokeLater. If you remove the initUniverse method from the constructor then you can create your universe object in the main method and then call initUniverse on the EDT with invokeLater.

You can create swing components off of the EDT. You just can't modify them after they've been realized off of the EDT.

It is considered a bug to create Swing components off the EDT. It used to be considered okay (if they were un-"realized"), but things changed. You just aren't allowed to do it at all now. The problem is that you don't know what sort of listeners and things get called.. For example, simply adding components to a Swing hierarchy will fire events... so the hierarchy must be built on the EDT.

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