I’m trying to implement my own progress bar. I have a constructor, that inits my progress bar and method to draw it:
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
}
so, that class draws my progress bar with any cursor location. since that, all works perfect.
I have a method that should redraw my progress bar , to set cursor to another location:
public void SetProgress (int p) {
Progress = p;
if (Progress<Minimum) Progress = Minimum;
if (Progress>Maximum) Progress = Maximum;
this.paint(g);
}
but it draw nothing. Am i missing something? How to redraw field?
just call invalidate and that should repaint the screen.
so replace
this.paint(g)withinvalidate();