Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Problem with graphics

 
Derek Boring
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24211
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Derek Boring
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It Worked!
Looks alot nicer now!

Thanks a ton!!!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic