1 package thinlet.drafts; 2 3 import java.awt.*; 4 import thinlet.*; 5 6 public class ProgressMonitor implements Runnable { 7 8 public void start(Thinlet thinlet) throws Exception { 9 thinlet.add(thinlet.parse("progressdialog.xml", this)); 10 } 11 12 private Thinlet thinlet; 13 private Object dialog, status, progressbar; 14 private Image icon; 15 private Thread thread; 16 private boolean stopped; 17 18 public void init(Thinlet thinlet, 19 Object dialog, Object status, Object progressbar, Image icon) { 20 this.thinlet = thinlet; 21 this.dialog = dialog; this.status = status; this.progressbar = progressbar; 22 this.icon = icon; 23 thread = new Thread (this); 24 stopped = false; 25 thread.start(); 26 } 27 28 public void run() { 29 for (int i = 1; !stopped && (i <= 10); i++) { 30 thinlet.setString(status, "text", "Completed " + i + " out of 10."); 31 thinlet.setInteger(progressbar, "value", i * 10); 32 try { 33 Thread.sleep(450); 34 } catch (InterruptedException ie) {} 35 } 36 icon.flush(); thinlet.remove(dialog); 38 } 39 40 public void close() { 41 stopped = true; 42 thread.interrupt(); 43 } 44 45 public void cancel() { 46 stopped = true; 47 thread.interrupt(); 48 } 49 } | Popular Tags |