  // Swing JProgressBar Example - Derek Molloy

  import javax.swing.*;
  import java.awt.*; 
  import javax.swing.border.*;

  public class JProgressBarExample extends JFrame
  {	
	JProgressBar progressBar;
	JLabel	progressLabel;

	public JProgressBarExample()
	{
		super("JProgressBar Example");

		JPanel p = new JPanel();
		p.setLayout(new BoxLayout(p, BoxLayout.X_AXIS));
		p.setBorder(new TitledBorder("Current Progress:"));

		progressBar = new JProgressBar(JProgressBar.HORIZONTAL,0,100);
		progressLabel = new JLabel(" 0%");
		p.add(progressBar);
		p.add(progressLabel);
		
		this.getContentPane().add(p);

		this.pack();	// set the size automatically
		this.show();	// display the frame

		this.updateProgress(50);
	}

	private boolean updateProgress() { return updateProgress(1); };
	private boolean updateProgress(int updateAmount)
	{
		int current = progressBar.getValue();
		int updateTo = current + updateAmount;
		if (updateTo < 100 && updateTo > 0) 
		{
			progressBar.setValue(updateTo);
			progressLabel.setText(" " + updateTo + "%");
		}
		else return false;
		return true;
	}
	
	
	public static void main(String[] args)
	{
		new JProgressBarExample();
	}
  }

