Never call getGraphics() of a Component in client code.Never invoke update(...) or any painting methods (other than repaint())directly, and never override the update() method for a Swing component.
As far as your problem is concerned, you really need to go through the tutorial on
Concurrency in Swing. And didn't you read the API for
JProgressBar? There's a link there to the tutorial on How to Monitor Progress which would have provided adequate guidance.