Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p><em>"Abandon all hope, ye who enter [through Swing to create games]!"</em></p> <p>To answer your question, JPanels are just a surface to draw on, like a chalkboard, or a piece of paper. They have nothing to do with stages, or anything else other than being a thing you can draw on, and a container for other sub-components.</p> <p>To address the game-specific question, I'd recommend you don't waste your time using Swing components to build a game interface. While it's <em>possible</em>, you're going to run into a bunch of performance problems that will just eat up your time. Based on your question you're already thinking about low-level stuff like Timers to schedule things, and overriding the <code>paintComponent()</code> method - a very common mistake, and a road that many a failed project spend time on just to find out it's not the best way.</p> <p>If your question were literally a path in a forest that you could see, you would notice these things:</p> <ul> <li>It is well trodden (as it seems to be the most direct approach)</li> <li>Just around the corner are several spiky death pits of performance, and obscure, non-cross-platform compatible tweaks</li> <li>You have to figure out how to use Swing's painting manager to do what you want, when in most cases for most games, you want direct, deterministic control over your rendering pipeline/process</li> <li>It is littered with the bodies of projects that try to use Swing for games, for weird (and silly) reasons such as, "I wanted to build a game that only uses the standard Java library." Well, the standard library is nice and all, but at its heart it was designed to solve business problems, and be really good at server and networking software, among other things. If you're not using at least some gamedev libraries, you're probably missing out on using the right tool for the right job. Swing was definitely not built to be used by games, as it serves basically no needs that game developers have, unless you're talking about the desktop apps/tools to <strong>build and edit</strong> levels and that sort of thing.</li> </ul> <p>Instead, use something like <a href="http://slick.cokeandcode.com/" rel="noreferrer">Slick2D</a> (for 2D games), or <a href="http://jmonkeyengine.com/" rel="noreferrer">jMonkeyEngine</a> for 3D shtuff. These libraries are designed <em>specifically</em> for building games, and are going to save you from having to reinvent the proverbial wheel, just to get your game up and going. They also have their own communities that can help you with library-specific issues.</p> <p>On top of that, they have already solved some of the trickiest cross-platform issues, like dealing with various versions of OpenGL, and other technical details that I'll bet you don't really care about when at the end of the day, what you really want is, "Hey, just give me an [arbitrary resolution], graphics-accelerated surface to draw on, and don't make it complicated!"</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload