Go Back   CodingForums.com > :: Server side development > Java and JSP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 02-26-2012, 04:39 PM   PM User | #1
javarower
New to the CF scene

 
Join Date: Feb 2012
Posts: 9
Thanks: 2
Thanked 0 Times in 0 Posts
javarower is an unknown quantity at this point
Need help understanding doublebuffer

Hi, I am new to java programming and am trying to make a very basic game. I would like to make a full screen gui with the code:
JFrame frame = new JFrame();
frame.setIgnoreRepaint(true);
frame.setBounds(new Rectangle(new Point(0, 0), tk.getScreenSize()));
frame.setUndecorated(true);
frame.setVisible(true);
and then make the gui print our a graphic.
My problem is that the only way i know how to put stuff on the screen is with the paint(Graphics g) method and this forces me to put all my logic into the paint(Graphics g) method. I was wondering if there was a way to create a graphic outside of the paint method(with like drawImage(Image, int, int, ImageObserver)) and then feed it into the paint method. Thank you in advance for helping me.
javarower is offline   Reply With Quote
Old 02-26-2012, 04:45 PM   PM User | #2
javarower
New to the CF scene

 
Join Date: Feb 2012
Posts: 9
Thanks: 2
Thanked 0 Times in 0 Posts
javarower is an unknown quantity at this point
IN the end this is what i want:

imports

public class Core{
public Core(){ //constructor
//JFrame code
update()
}
public static void main(String args[]){
Core gui=new Core();
}
public void update(){
Graphic g;
//game logic decides what to draw on graphic
paint(g); //Feed the created graphic into paint
}
public void paint(Graphic g){
//Put graphic on screen?
}
}
javarower is offline   Reply With Quote
Old 02-26-2012, 06:29 PM   PM User | #3
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,650
Thanks: 4
Thanked 2,451 Times in 2,420 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
Graphics can be retrieved off of any Graphical component using .getGraphics(). This will return the Graphic in use.
Best I can describe the idea behind double buffering for the graphics is you track two sets of graphics: your graphic with the intent of being what the graphic will be, and the internal graphic that is. You paint everything you need to your graphic and then swap the graphics during a repaint which minimizes the flicker over using individual component updates.
Here's an example of double buffering. Its used in an applet, but its logic is identical to using it in a Frame: http://www.realapplets.com/tutorial/...Buffering.html. Its usage overrides that of the paint and update methods to handle the double buffering. It looks like the easiest tutorial I could find, but doesn't explain why it works (for which you can try to google a few more for the actual ideas behind double buffering, there are a lot of good examples with step by step as to what does what).
Fou-Lu is offline   Reply With Quote
Users who have thanked Fou-Lu for this post:
javarower (02-27-2012)
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 06:50 PM.


Advertisement
Log in to turn off these ads.