aspose file tools*
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 Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Problem with graphics" Watch "Problem with graphics" New topic
Author

Problem with graphics

Derek Boring
Ranch Hand

Joined: Aug 15, 2006
Posts: 63
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
Marshal

Joined: Jul 08, 2003
Posts: 24187
    
  34

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: 63
It Worked!
Looks alot nicer now!

Thanks a ton!!!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Problem with graphics