I'm making a game. This game uses a single timer, which executes a "step" event in all of the game's objects, then calls repaint, which calls repaint in all of the game's objects. The objects do not have their own container, they all draw themselves directly to the JFrame's graphics object. The problem is that the graphics tend to glitch. Horizontal lines keep randomly appearing. The lines are the color of the background, or the graphics below whatever is being painted, and disappear the next time repaint is called. I know enough about graphics to know that if I can synchronise the call to repaint with the montor's vertical sweeps, I may be able to eliminate the glitch. I just don't have any idea how to do that.
I could be wrong and it could be something entirely different. If anyone with graphics experience could help me it would be greatly appreciated.
Life is 10% what happens and 90% how you react to it.
Attitude is everything.
Instead of drawing directly on the JFrame, add a JPanel subclass instance to your JFrame and draw on that (from within the JPanel's paintComponent() method). JPanels do double-buffering for you by default, which is just what you need.