skip to main | skip to sidebar

Java Programs and Examples with Output

Pages

▼
 
  • RSS
  • Twitter
Saturday, October 13, 2012

Create Progress Bar in Swing

Posted by Raju Gupta at 11:00 PM – 0 comments
 
It will demonstrate the Progress Bar creation in Swing

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JProgressBar;

public class ProgressBar extends JFrame {
 JProgressBar current = new JProgressBar(0, 2000);
 int num = 0;

 public ProgressBar() {
  //exit button
  setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  //create the panel to add the details
  JPanel pane = new JPanel();
  current.setValue(0);
  current.setStringPainted(true);
  pane.add(current);
  setContentPane(pane);
 }

 //to iterate so that it looks like progress bar  
 public void iterate() {
  while (num < 2000) {
   current.setValue(num);
   try {
    Thread.sleep(1000);
   } catch (InterruptedException e) {
   }
   num += 95;
  }
 }

 //for testing the app
 public static void main(String[] arguments) {
  ProgressBar frame = new ProgressBar();
  frame.pack();
  frame.setVisible(true);
  frame.iterate();
 }
}


Labels: Java Swing Example , Progress Bar Example

Leave a Reply

Newer Post Older Post
Subscribe to: Post Comments ( Atom )
  • Popular
  • Recent
  • Archives
Powered by Blogger.
 
 
 
© 2011 Java Programs and Examples with Output | Designs by Web2feel & Fab Themes

Bloggerized by DheTemplate.com - Main Blogger