package examples; import javax.swing.JProgressBar; public class ProgressLoop extends JProgressBar implements Runnable { private static final long serialVersionUID = 1L; static int sharedValue = 0; public ProgressLoop() { super(0, 100); // start and maximum values } void rest(int milliseconds) { try { Thread.sleep(milliseconds); } catch (InterruptedException ie) { // wake up } } static int getSharedValue() { return sharedValue; } static void setSharedValue(int value) { sharedValue = value; } public void run() { for (int i = 1; i <= 100; i++) { int x = getSharedValue(); setValue(i); // set the progress bar value setSharedValue( x + 1); rest(10); } } }