🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: aus.computers.java
3 messages
3 total messages Started by Mario Dima Thu, 30 Nov 2000 07:14
JProgress Bar
#380
Author: Mario Dima
Date: Thu, 30 Nov 2000 07:14
12 lines
1960 bytes
I have an application that processes some files, and it I want a visual
indication of the processing.  What better than a JProgress bar.  So I start
by studying the documentation and all of the books that I have, as well as
all my web resources, but nowehre can I com up with a stright forward
example of how to use a JProgress bar.  All I want is to give it the total
number of files to be processed, and tell it to increment every time a file
is finished, and perhaps a string diplaying the file name.

All help is appreciated.

TIA
Mario
Re: JProgress Bar
#383
Author: Dennis Bulai
Date: Thu, 30 Nov 2000 00:00
98 lines
4661 bytes
Here's a quick and dirty example of using a progress monitor.  All it does
is read in its own source file character by character, maintain a character
count and periodically update the JProgressMonitor.  The sleep in the update
thread isn't really necessary to functionality, it just slows things down
enough to see actual operation of the PM

import java.io.*;
import javax.swing.*;
import java.awt.event.*;


public class ProgMon   {



    public static void main(String[] args){
        final JFrame frame = new JFrame("Progress Test");
        JButton button  = new JButton("Start");
        int min =0;
        final int max = 25000;
        String[] message = new String[2];
        message[0] = "Performing operation";
        message[1] = "..This will take time..";
        final ProgressMonitor monitor = new ProgressMonitor(frame,
message,"Iteration",min,max);
        final Runnable runnable = new Runnable() {
            public void run(){
                int sleepTime = 50;
                int counter = 0;

                    try {
                        try{
                            FileInputStream fis = new
FileInputStream("AddUserGUI.java");
                            int ch;
                            while ((ch = fis.read()) >= 0){
                                counter++;

                                if (counter % 100 == 0){
                                    Thread.sleep(sleepTime);
                                    System.out.println(counter);
                                    monitor.setProgress(counter);
                                }
                            }
                        }
                        catch( Exception ie){ ie.printStackTrace();
                        }
                        System.out.println("loaded "+counter);
                    //  monitor.setNote("Iteration "+counter);
                    //  monitor.setProgress( counter/max);
                        if (monitor.isCanceled()){
                            monitor.setProgress( 100 );
                        //  break;
                        }
                        //Thread.sleep(sleepTime);
                    }
                    catch (Exception dontcare){
                    }

                monitor.close();
            }
        };
        button.addActionListener( new ActionListener() {
            public void actionPerformed(ActionEvent a){
                Thread thread = new Thread(runnable);
                thread.start();
            }
        });
        frame.addWindowListener(new WindowAdapter(){
            public void windowClosing(WindowEvent we){
                frame.setVisible(false);
                frame.dispose();
                System.exit(1);
            }
        });
        frame.getContentPane().add(button);
        frame.pack();
        frame.setVisible(true);
    }
}

DB
Mario Dima wrote in message ...
>I have an application that processes some files, and it I want a visual
>indication of the processing.  What better than a JProgress bar.  So I
start
>by studying the documentation and all of the books that I have, as well as
>all my web resources, but nowehre can I com up with a stright forward
>example of how to use a JProgress bar.  All I want is to give it the total
>number of files to be processed, and tell it to increment every time a file
>is finished, and perhaps a string diplaying the file name.
>
>All help is appreciated.
>
>TIA
>Mario
>
>
Re: JProgress Bar
#384
Author: droo
Date: Thu, 30 Nov 2000 23:30
19 lines
2112 bytes
A search on google.com took me approximately 5
earth seconds to locate an example...

http://www.cs.cf.ac.uk/Dave/HCI/HCI_Handout_CALLER/node127.html

Mario Dima wrote:
> 
> I have an application that processes some files, and it I want a visual
> indication of the processing.  What better than a JProgress bar.  So I start
> by studying the documentation and all of the books that I have, as well as
> all my web resources, but nowehre can I com up with a stright forward
> example of how to use a JProgress bar.  All I want is to give it the total
> number of files to be processed, and tell it to increment every time a file
> is finished, and perhaps a string diplaying the file name.
> 
> All help is appreciated.
> 
> TIA
> Mario
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads