private void paint3(Graphics gra, int x, int y, int w, int h, int r, int g,
int b, int k,int width) {
String s=w*100/width+"%";
System.gc();
gra.setColor(0);
gra.fillRect(x, y-h/2, width, h);
for (int i = 0; i < h / 2; i++) {
if (r > 0) {
r -= k;
if (r < 0)
r = 0;
}
if (g > 0) {
g -= k;
if (g < 0)
g = 0;
}
if (b > 0) {
b -= k;
if (b < 0)
b = 0;
}
// if (k3 == i || k2 == i) {
// gra.setColor(255, 138, 0);
// } else {
gra.setColor(r, g, b);
//}
gra.drawLine(x, y + i, x + w, y + i);
gra.drawLine(x, y - i, x + w, y - i);
}
gra.setColor(30,230,30);
gra.drawRect(x, y-h/2, width, h);
gra.setColor(0xffffff);
gra.drawString(s,x+width/2, y+5, Graphics.HCENTER|Graphics.BASELINE);
}
int num=0;
void paint(Graphics g){
if(num<200){
num++;
}
paint3(g,20,250,num,20,30,230,30,30,200);
}
效果如下: