Hi !
Featured games (85)
games approved by the League of Dukes
Games in Showcase (623)
Games in Android Showcase (176)
games submitted by our members
Games in WIP (676)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Question regarding a double buffer example (at javaworld).  (Read 898 times)
0 Members and 2 Guests are viewing this topic.
Offline DonaldEKnuth

Junior Devvie

« Posted 2005-12-08 00:22:59 »


I have looked at and its example 7. It is an example demonstrating moving images on top of each other using double buffering as the update method (implemented "by hand", not  using strategy).

Its update method looks like this:

    public void update(Graphics g) {
   Dimension d = size();

   // Create the offscreen graphics context
   if ((offGraphics == null)
    || (d.width != offDimension.width)
    || (d.height != offDimension.height)) {
       offDimension = d;
       offImage = createImage(d.width, d.height);
       offGraphics = offImage.getGraphics();

   // Erase the previous image
   offGraphics.fillRect(0, 0, d.width, d.height);

   // Paint the frame into the image

   // Paint the image onto the screen
   g.drawImage(offImage, 0, 0, null);

The complete applet code with update() within its example context.

I am wondering why the part titled "Create the offscreen graphics context" in that method checks if the offGraphics exists, and if it doesn't creates it. Why didn't they create it in the init() method instead? They also check if the size has changed, can the size of an applet change at run time? (And if they can, can i prevent this so that I don't need to check for creation at each update() call?)

My 4k 2006 Entry: Sokoban4k
Offline swpalmer

JGO Coder

Exp: 12 years

Where's the Kaboom?

« Reply #1 - Posted 2005-12-08 00:32:25 »

They probably put the code there so it would be in one place, since they were checking for size changes anyway.

I think it is possibel to change the size of an applety dynamically, but it is not common.  I don't know what the normal method for doing it would be.  Perhaps some jscript and manipulating the size in the DOM?

Offline DonaldEKnuth

Junior Devvie

« Reply #2 - Posted 2005-12-08 00:52:09 »

Thanks for your reply. I thought that I would use setResizable(false); in the init() method, but it's not available. Still I can set my own applet size from that method using (in my case) setSize(400, 400);. A bit strange, I guess it won't be a problem.

My 4k 2006 Entry: Sokoban4k
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline jbanes

JGO Coder

Projects: 1

"Java Games? Incredible! Mr. Incredible, that is!"

« Reply #3 - Posted 2005-12-08 01:19:46 »

I think it is possibel to change the size of an applety dynamically, but it is not common.  I don't know what the normal method for doing it would be.  Perhaps some jscript and manipulating the size in the DOM?

I managed to crash both Netscape and IE when I tried that stunt back in the day. These days I'd just do it in AJAX. Smiley

Java Game Console Project
Last Journal Entry: 12/17/04
Pages: [1]
  ignore  |  Print  
You cannot reply to this message, because it is very, very old.

BurntPizza (22 views)
2015-10-08 03:11:46

BurntPizza (15 views)
2015-10-08 00:30:40

BurntPizza (17 views)
2015-10-07 17:15:53

BurntPizza (32 views)
2015-10-07 02:11:23

KaiHH (37 views)
2015-10-06 20:22:20

KaiHH (16 views)
2015-10-06 19:41:59

BurntPizza (32 views)
2015-10-06 19:04:48

basil_ (46 views)
2015-09-30 17:04:40

shadowstryker (24 views)
2015-09-29 15:55:06

TheSpaceHedgehog (31 views)
2015-09-29 01:58:48
Math: Inequality properties
by Roquen
2015-10-01 13:30:46

Math: Inequality properties
by Roquen
2015-09-30 16:06:05

HotSpot Options
by Roquen
2015-08-29 11:33:11

Rendering resources
by Roquen
2015-08-17 12:42:29

Rendering resources
by Roquen
2015-08-17 09:36:56

Rendering resources
by Roquen
2015-08-13 07:40:51

Networking Resources
by Roquen
2015-08-13 07:40:43

List of Learning Resources
by gouessej
2015-07-09 11:29:36 is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!