1 package org.catacomb.graph.gui; 2 3 4 public class MovieFramePlayer implements Runnable { 5 6 MovieDisplay movieDisplay; 7 8 boolean shouldStop; 9 10 11 public MovieFramePlayer(MovieDisplay md) { 12 movieDisplay = md; 13 shouldStop = false; 14 } 15 16 17 public void stop() { 18 shouldStop = true; 19 } 20 21 22 public void start() { 23 Thread thread = new Thread(this); 24 thread.setPriority(Thread.MIN_PRIORITY); 25 thread.start(); 26 } 27 28 29 30 31 public void run() { 32 while (movieDisplay.canAdvance()) { 33 34 double spd = movieDisplay.getSpeed(); 35 36 int msecs = (int)(20. / spd); 37 38 try { 39 Thread.sleep(msecs); 40 } catch (Exception ex) { 41 42 } 43 44 if (shouldStop) { 45 break; 46 } 47 48 if (movieDisplay.canAdvance()) { 49 movieDisplay.advance(); 50 } 51 } 52 53 } 54 55 56 }