Monday, 10 September 2018

Swing Multi Frame Progress Bar Example


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








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

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

class Frame1 extends JFrame implements ActionListener
{
JButton b1=new JButton("New Frame");
JProgressBar p=new JProgressBar(0,100);
int i=0;

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

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

Timer t=new Timer(100,this); 

b1.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent ae)
  {
   t.start();
  } 
});
  
}

public void actionPerformed(ActionEvent ae)
  {  
     p.setValue(i);
     i++;
     if(i==100)
     {
       Frame2 obj2=new Frame2();
       dispose();
     }
   
  }

}

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

JLabel l1=new JLabel("Welcome To New Frame");
add(l1);
}





  

How To Run: 

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

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


  

No comments:

Post a comment