File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Swing / AWT / SWT and the fly likes Problem with graphics Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Problem with graphics" Watch "Problem with graphics" New topic

Problem with graphics

Derek Boring
Ranch Hand

Joined: Aug 15, 2006
Posts: 65
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.
Ernest Friedman-Hill
author and iconoclast

Joined: Jul 08, 2003
Posts: 24199

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.

[Jess in Action][AskingGoodQuestions]
Derek Boring
Ranch Hand

Joined: Aug 15, 2006
Posts: 65
It Worked!
Looks alot nicer now!

Thanks a ton!!!
I agree. Here's the link:
subject: Problem with graphics
jQuery in Action, 3rd edition