home *** CD-ROM | disk | FTP | other *** search
Java Source | 2000-08-18 | 1.8 KB | 67 lines |
- //AdvSiteSearcher c1999 The Gilbert Post by David Faden
- //The applet and code are distributed as linkware...
- //If you use this applet or a variant on its code,
- //include a link to The Gilbert Post,
- //http://www.geocities.com/Athens/Parthenon/1911
- //The Gilbert Post and David Faden take no responsibility
- //for anything bad that happens as a result of using this applet
- //or a derivative based on its code. USE AT YOUR OWN RISK. (big letters)
- //Please send reports of problems to gilbertnews@hotmail.com, anyway, though.
-
- //begin ProgressBar.java
- import java.awt.*;
-
- //Displays the percent of a task done
- class ProgressBar extends Canvas {
- private Color oncolor;
- private Color offcolor;
- private String onmessage;
- private int width;
- private int height;
- private int max;
- private int currtotal=0;
-
- public ProgressBar(Color oncolor,Color offcolor,int width,int height,int max,String onmessage) {
- this.oncolor=oncolor;
- this.offcolor=offcolor;
- this.width=width;
- this.height=height;
- this.max=max;
- this.onmessage=onmessage;
- resize(width,height);
- }
-
- //Assuming i is positive
- public int plus(int i) {
- if(currtotal<max) currtotal+=i;
- repaint();
- return currtotal;
- }
-
- public void reset() {
- currtotal=0;
- repaint();
- }
-
- public void setMax(int i) {
- max=i;
- repaint();
- }
-
- public void paint(Graphics g) {
- g.setColor(offcolor);
- g.fillRect(0,0,width,height);
- if(currtotal>0) {
- double perc=(double)currtotal/(double)max;
- if(perc>1.0D) perc=1.0D;
- int drawwidth=(int)((double)(width-2)*perc);
- g.setColor(oncolor);
- g.fillRect(1,1,drawwidth,height-2);
- int iperc=(int)(100.0*perc);
- g.setColor(Color.black);
- g.drawString(onmessage+" "+iperc+"%",4,height-5);
- }
- }
-
- }//end ProgressBar.java
-