Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Help with JProgressBar

MarbaMarba Posts: 1Member
Hello i'm trying to do a progressbar with this code, but the bar don't get filled progressively, it waits till the end and then it shows 100%

Can u help me plz?



import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;


public class ProgressBarTest extends JApplet implements ActionListener
{
private JPanel panel;
private Container c;
private JButton button;
private JProgressBar bar;

public void init()
{
c=getContentPane();
panel= new JPanel();
button= new JButton("Start...");
button.addActionListener((ActionListener) this);
bar= new JProgressBar(0,100);
bar.setStringPainted(true);

button.setBounds(0, 20, 100, 30);
bar.setBounds(40, 20, 200, 30);

panel.add(button);
panel.add(bar);

c.add(panel);
setSize(400,100);
}

public void actionPerformed(ActionEvent e)
{
for(int h=0;h<=100;h++)
{
bar.setValue(h);
System.out.println("Value= "+h);
wait(60);
}
}

public static void wait (int n)
{
long t0,t1;
t0=System.currentTimeMillis();
do
{
t1=System.currentTimeMillis();
}
while (t1-t0<n);
}
}


Sign In or Register to comment.