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);
}
}