How do I load images (possibly for animation) without flickering?
Created May 4, 2012
Rahul kumar Gupta To Load an images without flickering then you have use the concept called double buffering.
Steps to be followed
- create an object of image class
- create and object of Mediatracker class
- add image object to Mediatracker
- check whether image is loaded or not before painting
Here is an example
class SomeClass { MediaTracker tracker; Image img; ... //adding image to tracker tracker = new MediaTracker(this); tracker.addImage(img,0); } public void paint(Graphics g) { // waiting to get image loaded photochecked(0); g.drawImage(img,0,0,this); } //method that will return true if particular image is loaded public boolean photochecked(int no) { int pchecked=no; while(pchecked ==no) { if(tracker.checkID(no,true)) pchecked++; } return true; } }