Monday, 10 September 2018

Swing Progress Bar Example


                      In this post, we will see how to use Progress Bar in Java Swing Program.
                       Go through the following program.








Program (SwingProgressBar.java)
import javax.swing.*;  
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

public class SwingProgressBar
{
public static void main(String args[])
{
Abc obj=new Abc();
}
}

class Abc extends JFrame 
{
JLabel l1=new JLabel("Name");
JTextField t1=new JTextField(20);
JButton b1=new JButton("Submit");
JProgressBar p=new JProgressBar(0,1000);
int i=0;

public Abc()
{
setVisible(true);
setSize(250,400);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLayout(new FlowLayout());

add(l1);
add(t1);
add(b1);
add(p);
p.setStringPainted(true); 

while(i<=1000)
{
try{Thread.sleep(10);}catch(Exception e){}
p.setValue(i);
i++;
}

}



  

How To Run on Terminal: 

parag@parag-Inspiron-N4010:~/Desktop/swing$ javac SwingProgressBar.java

parag@parag-Inspiron-N4010:~/Desktop/swing$ java SwingProgressBar


  

No comments:

Post a comment