Java

Moderators: zibadian
Number of threads: 7836
Number of posts: 18235

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
Help with JProgressBar Posted by Marba on 12 Apr 2011 at 5:39 PM
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);
}
}





 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.