13.07.2015 Views

Multithreaded Graphics - Custom Training Courses - Coreservlets.com

Multithreaded Graphics - Custom Training Courses - Coreservlets.com

Multithreaded Graphics - Custom Training Courses - Coreservlets.com

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Double Buffering: Examplepublic void run() {while(running) {for(MovingCircle circle: circles) {circle.move(width, height);}repaint();pause(100);}}public void update(<strong>Graphics</strong> g) {paint(g);}public void paint(<strong>Graphics</strong> p g) {offScreen<strong>Graphics</strong>.clearRect(0, 0, width, height);for(MovingCircle circle: circles) {circle.draw(offScreen<strong>Graphics</strong>);}g.drawImage(offScreenImage, 0, 0, this);}27Double Buffering: Result28At the expense of memory and some <strong>com</strong>plexity, double buffering allows fast,flicker-free updating of possibly overlapping images

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!