I've got this program which saves data into TXT files and it takes very long to do so. The problem is not how long it take though, the more annoying problem is that everything in my program is blocked until it's done saving and doesn't notif the user of what's going on.... What I mean is I want a message (i was thinking a little window) to appear where saying "Saving..." and disappearing when the program is done saving.
Which SWING class would the best to do this? I was thinking of using JOptionPane but those windows come with buttons... which is unnecessary
Must I create an extension of the JFrame class or is there an alternative?
Any suggestion will be much appreciated
P.S. I was also thinking of adding a progress bar and I could
> the more annoying problem is that everything in my program is blocked until it's done saving and doesn't notif the user of what's going on....
if you're doing this via actionPerformed() or similar listener, you're probably blocking the swing thread (EDT),
in which case it would be better to save the data via a separate thread, thus leaving your GUI 'responsive',
then perhaps you wouldn't need a progress bar, as the data would be being saved in the background
Oh there's a class called JProgressBar... logically that's what I'm looking for.
I've checked out the SwingWorker class but we're not allowed to use this since it's part of Java 6 (and this project is meant to be coded in Java 5). What is the best alternative?
So far my efforts reveal a problem which seems to be what Michael Dunn pointed out:
I have an algorithm that looks somewhat like this:The problem with this is that the bar doesn't move as the data is being saved. Instead it just magically goes from 0 to 100 when the process is done (which through my understanding seems to be a Thread problem is everything else works when I test it on its own). So to try get around this problem I changed my algorithm a bit to something like:But I still get a similar problem....
I pressume I need to take my first algorithm and run it on a separate Thread but I don't understand why my second algorithm doesn't work :S could anyone please explain this.
I'm pretty sure that SwingWorker was a class that appeared in tutorials and web articles going back several years, and it was only inducted into Java recently. So if you could track down one of those articles you could get the code for it and use it in your project (legalisms permitting, of course).