modified MyProgBar.java
+ added constructors * Fixed bug with percentage display
This commit is contained in:
@@ -12,9 +12,22 @@ class MyProgBar extends Canvas {
|
|||||||
Color bgColor = Color.lightGray;
|
Color bgColor = Color.lightGray;
|
||||||
Color txColor = Color.white;
|
Color txColor = Color.white;
|
||||||
|
|
||||||
|
public MyProgBar(int min, int max, int pos) {
|
||||||
|
super();
|
||||||
|
this.minVal = min;
|
||||||
|
this.maxVal = max;
|
||||||
|
this.curVal = pos;
|
||||||
|
}
|
||||||
|
|
||||||
|
public MyProgBar(int min, int max) {
|
||||||
|
super();
|
||||||
|
this.minVal = min;
|
||||||
|
this.maxVal = max;
|
||||||
|
}
|
||||||
|
|
||||||
public void paint(Graphics g) {
|
public void paint(Graphics g) {
|
||||||
double percentage = (double)(curVal-minVal)/(double)(maxVal-minVal);
|
double percentage = (double)(curVal-minVal)/(double)(maxVal-minVal);
|
||||||
String percString = Double.toString(percentage*100) + "%";
|
String percString = String.valueOf((int)(percentage*100)) + "%";
|
||||||
g.setFont(new Font("Dialog", Font.PLAIN, 10));
|
g.setFont(new Font("Dialog", Font.PLAIN, 10));
|
||||||
FontMetrics fm = getFontMetrics(g.getFont());
|
FontMetrics fm = getFontMetrics(g.getFont());
|
||||||
g.setColor(bgColor);
|
g.setColor(bgColor);
|
||||||
|
|||||||
Reference in New Issue
Block a user