Friday, 24 January 2014

Write a program to create Progress Bar using Swing in JAVA

import javax.swing.*;
import java.awt.*;

class progDemo extends JFrame
{
    JProgressBar jpb = new JProgressBar(0,100);
    progDemo()
    {
        setVisible(true);
        setSize(400,400);
        setLayout(new FlowLayout());
        add(jpb);
        
        Thread t = new Thread(new Runnable(){
                public void run()
                {
                    try
                    {
                        for(int i=0;i<=100;i++)
                        {
                            jpb.setValue(i);
                            Thread.sleep(100);
                        }
                    }
                    catch(Exception e){System.out.println(e);}
                } 
        });
        t.start();
        
    }
    public static void main(String s[])
    {
        new progDemo();
    } 
}


OUTPUT 

0 comments:

Post a Comment

Followers