我试图实现自己的进度条。我有一个构造函数,它在我的进度条和方法中绘制它:
protected void paint(Graphics graphics)
{
g = graphics; //remember graphics to redraw it later
ResizeImage r = new ResizeImage();
Picture = r.sizeImage(Picture, Width, Height);
graphics.drawBitmap(1, 1, Width, Height, Picture.getBitmap(), 0, 0); //dwaring background
Cursor = r.sizeImage(Cursor, Height, Height);
graphics.drawBitmap(1+(Width-Height*2)*Progress/(Maximum - Minimum), 1, Height, Height, Cursor.getBitmap(), 0, 0); //drawing cursor
}
所以,该类使用任何光标位置绘制我的进度条。从那以后,一切都很完美。 我有一个方法应该重绘我的进度条,将光标设置到另一个位置:
public void SetProgress (int p) {
Progress = p;
if (Progress<Minimum) Progress = Minimum;
if (Progress>Maximum) Progress = Maximum;
this.paint(g);
}
但它什么都没画。我错过了什么吗? 如何重绘字段?
答案 0 :(得分:0)
只需调用invalidate即可重新绘制屏幕。
所以用this.paint(g)
invalidate();