Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > How use progress bar into applet?

Reply
Thread Tools

How use progress bar into applet?

 
 
Derek
Guest
Posts: n/a
 
      08-21-2003
Can you write me an example, please?.

And, I´m using Swing.

Thanks.



 
Reply With Quote
 
 
 
 
Lauwie
Guest
Posts: n/a
 
      08-21-2003
Derek wrote:
> Can you write me an example, please?.
>
> And, I´m using Swing.
>


Here's a simple example, hope it helps:

public class ProgressApplet extends JApplet implements ActionListener
{

private JProgressBar progressBar;
public void init()
{

getContentPane().setBackground(Color.WHITE);
getContentPane().setLayout(new FlowLayout());

progressBar = new JProgressBar();
getContentPane().add(progressBar);

JButton cmd = new JButton("Do Task");
cmd.addActionListener(this);
getContentPane().add(cmd);
}

/**
* @see java.awt.event.ActionListener#actionPerformed(Acti onEvent)
*/
public void actionPerformed(ActionEvent e)
{
new Worker().start();
}

private class Worker extends Thread
{
private void updateBar(Runnable runner)
{
try
{
SwingUtilities.invokeAndWait(runner);
}
catch (Exception e)
{
}
}
public void run()
{
progressBar.setValue(0);
progressBar.setMinimum(0);
progressBar.setMaximum(100);

//do your task here
for (int x = 0; x < 100; x++)
{

//sample task
try
{
Thread.sleep(10L);
}
catch (Exception e)
{
}
//

final int current = x;
updateBar(new Runnable()
{
public void run()
{
progressBar.setValue(current);
}
});
}

}
}
}

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Integrate Windows Media Player progress bar into taskbar or tray. Skybuck Flying Windows 64bit 2 06-30-2011 06:15 AM
Progress bar to show the progress of a task Charlie Zhang Java 3 08-16-2004 05:53 PM
How use progress bar into applet?. A lot of thanks, Lauwie Derek Java 1 08-22-2003 11:29 PM
How use a progress bar into applet? Derek Java 1 08-20-2003 05:49 PM
progress bar or guage bar Rob ASP General 6 07-12-2003 09:46 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57