JProgressBar

JProgressBar 

It is visually displays the progress of some task.

The setMinimum() and setMaximum() that creates the progress bar sets the progress bar’s minimum and maximum values.

setStringPainted(boolean value ) :

Sets the value of the stringPainted property, which determines whether the progress bar should render a progress string.

setValue():

The setValue method is used to set the current value on the progress bar to maximum value.

Thread.sleep():

The Thread.sleep() method tells the current thread to sleep for some number of milliseconds, letting other processes run.

 setString() :

The setString method is used to set value to the progress string.

Program

fggfgf

 

 

 

Program Source

import javax.swing.JFrame;
import javax.swing.JProgressBar;
import java.awt.Color;
import java.awt.FlowLayout;

class Frame extends JFrame {
    
    JProgressBar jp;
    
    Frame()
    {
        setTitle("JProgressBar");
        setLayout(new FlowLayout());
        setJProgressBar();
        setSize(700,200);
        setVisible(true);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setJProgressBarUpdate();
    }
    
    private void setJProgressBar()
    {
        jp = new JProgressBar();
        jp.setMinimum(0);
        jp.setMaximum(100);
        jp.setStringPainted(true);
        jp.setBackground(Color.CYAN);
        add(jp);
    }   
    
    private void setJProgressBarUpdate()
    {
        for(int i=0;i<=100;i+=10)
        {
            try{
                Thread.sleep(500);
            }catch(InterruptedException ie){}
            jp.setValue(i);
        }
        jp.setString("Done");
    }
}

public class Javaapp {
   
    public static void main(String[] args) {
        
       Frame fr = new Frame();
    }
}

Leave a Comment