GPWiki.org
GPWiki.org
It is currently Wed Jun 19, 2013 5:05 pm

All times are UTC




Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: Double Buffering JFrame
PostPosted: Sun Jan 04, 2009 4:21 pm 
Rookie

Joined: Sat Jan 03, 2009 11:56 pm
Posts: 2
Dear Forum users.
Im currently drawing to a JFrame using the paint function.

But I cant get it to double buffer, it flickers.. Tried using the guide thats on GPWIKI but still cant get it to work. Don't really understand it -.-.. I'v done a few applets and there its easy to make one..

Anyone that can help me out?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 04, 2009 11:23 pm 
Rookie

Joined: Wed Mar 04, 2009 11:10 pm
Posts: 2
An easy way of implementing double buffering for a JFrame is to use BufferStrategy (from awt.image)

After you construct the JFrame (and have made it visible) you can use:

Code:
myframe.createBufferStrategy(2);



When it comes time to draw stuff to the JFrame, you will need to reference the JFrame's BufferStrategy:

Code:
BufferStrategy mybufferstrategy = this.getBufferStrategy();



and then assign a graphics component to it:

Code:
Graphics g = mybufferstrategy.getDrawGraphics();



Finally, draw whatever you want to the graphics component and then display the contents of the buffer on the JFrame with:

Code:
mybufferstrategy.show();



Hope this helps.


Top
 Profile  
 
PostPosted: Tue Jul 05, 2011 5:41 am 
i used ur concept

but i couold not load images using thiss concept

pls help


Top
  
 
PostPosted: Fri Aug 19, 2011 3:51 am 
Octogenarian

Joined: Thu Aug 04, 2011 12:00 am
Posts: 87
Location: Arizona
You can use the Graphics2D system to draw with a JFrame without flicker.
Code:
BufferedImage backbuffer;
Graphics2D g2d;
backbuffer = new BufferedImage(640, 480, BufferedImage.TYPE_INT_RGB);
g2d = backbuffer.createGraphics();



Then, when you want to draw anything, use g2d.draw().

_________________
Amazon Author Page
Game Dev Forum
Facebook Page


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group