KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > thinlet > drafts > ProgressMonitor


1 package thinlet.drafts;
2
3 import java.awt.*;
4 import thinlet.*;
5
6 public class ProgressMonitor implements Runnable JavaDoc {
7     
8     public void start(Thinlet thinlet) throws Exception JavaDoc {
9         thinlet.add(thinlet.parse("progressdialog.xml", this));
10     }
11     
12     private Thinlet thinlet;
13     private Object JavaDoc dialog, status, progressbar;
14     private Image icon;
15     private Thread JavaDoc thread;
16     private boolean stopped;
17     
18     public void init(Thinlet thinlet,
19             Object JavaDoc dialog, Object JavaDoc status, Object JavaDoc 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 JavaDoc(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 JavaDoc ie) {}
35         }
36         icon.flush(); // animated gif refreshes the whole thinlet continuously
37
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