/* PImage loading runs in another thread, 1 at a time. */ final SynchronousQueue imgq = new SynchronousQueue(); volatile CopyOnWriteArrayList imgFileNames = null ; volatile int imgFileIndex = 0 ; class PImageLoader implements Runnable { private int imgFileIndex = 0 ; private volatile int lastputindex = 0 ; void run() { while(true) { PImage img = loadImage(imagedir + "/" + imgFileNames.get(imgFileIndex)); lastputindex = imgFileIndex ; boolean done = false ; while (! done) { try { imgq.put(img); done = true ; } catch (InterruptedException x) { } } imgFileIndex = (imgFileIndex+1) % imgFileNames.size(); } } int getDisplayedImageIndex() { return lastputindex ; } }