How use progress bar into applet?

Discussion in 'Java' started by Derek, Aug 21, 2003.

  1. Derek

    Derek Guest

    Can you write me an example, please?.

    And, I´m using Swing.

    Thanks.
     
    Derek, Aug 21, 2003
    #1
    1. Advertising

  2. Derek

    Lauwie Guest

    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(ActionEvent)
    */
    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);
    }
    });
    }

    }
    }
    }
     
    Lauwie, Aug 21, 2003
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Derek
    Replies:
    1
    Views:
    713
  2. Derek
    Replies:
    1
    Views:
    479
    Lauwie
    Aug 23, 2003
  3. Charlie Zhang
    Replies:
    3
    Views:
    1,340
    Paul Lutus
    Aug 16, 2004
  4. Mark Richards
    Replies:
    2
    Views:
    1,154
    Andrew Thompson
    Oct 8, 2004
  5. Rob

    progress bar or guage bar

    Rob, Jul 11, 2003, in forum: ASP General
    Replies:
    6
    Views:
    222
    Chris Barber
    Jul 12, 2003
Loading...

Share This Page