Matt Wong wrote:make sure all gui code runs in the EDT
EDT == Event Dispatch Thread.
In Java's GUI subsystems, you don't draw directly to the screen. You set up a "drawing program" that is then executed independently by a separate rendering thread. Roughly speaking, since the actual drawing these days is likely to be done via a GPU running dozens of hundreds of parallel threads.
The reason for this disconnect is that it makes it possible for graphics to render more smoothly and likewise the user interface (which is handled by the EDT). If you click a mouse button and that is supposed to make a square pop up in the game window, the EDT thread dispatches the mouse event to your click handler code which obtains whatever data it requires (presumably the mouse co-ordinates so you can draw a square there). The handler then adds a "draw a square" command to the graphics program, and invalidates the section of the display where the square will be drawn so that the rendering thread will then do the actual drawing. By setting a "clipping area" (usually one or more rectangles) you can save the overhead and flicker of re-drawing the unchanged parts of the display. This is also how the system handles overlapping windows and other stacked artefacts, where you don't need to draw something if something else is sitting on top of it.
Although everyone knows that
real games run at 320x200 pixels!
