Jeff Kish wrote:
> Hi.
> I have an swt app and I'm working in eclipse.
>
> I'm trying to figure out the best way to fit a status dialog up that
> will allow me to report records processed etc and make cancel /pause
> processing buttons available.
>
> I'm pretty rust so a pointer to a code snippet or actual code would be
> appreciated.
> Thanks
> Jeff
>
> p.s. here is my main. basically the'processingToDo' method puts up a
> couple of file dialogs to get input and output file names, and then
> reads one file and writes the other.
If possible, always post complete code that can be run. It doesn't help
to snip some methods... (If your code base in huge, see if you can
extract a code sample that is runnable in its own right, and that
demonstrates the problem or question.)
As a general point, your code is very procedural in style (i.e. sticking
loads of stuff into the main method). I presume you've not done much OO
(object orientation)? I ask because it's usual for the main method to
not be doing much at all apart from setting up a few things - e.g.
instantiating some objects, then calling methods on those objects to
kick everything off. I would work on solidifying your understanding of
OO and learning to program in a less procedural manner before moving
onto more advanced things like threading, GUIs, etc. Get comfortable
with walking before you start running and all that....
A more conventional OO way to do things is to separate your concerns
into independent parts (classes). One clear concern of your program is
the act of copying the file. Another concern is the reporting back of
the progress to the user in a dialog. Keep these concerns separate by
having a class for each: so, you could have a FileCopier[1] class, and a
ProgressDialog class.
[1] Obviously, if you really do want to be doing just file copying, look
at the existing options in Java for doing that task. Don't reinvent the
wheel.
As for examples of progress dialogs, did you try google? I googled for
"java progress dialog" and the third link was:
http://javaalmanac.com/egs/javax.swing/ProgMon.html
Try googling!
[[Some more advanced design concepts for later on: be aware that you
reduce the coupling between the copier class and the progress dialog
class (e.g. by using a software design pattern known as "Listener" AKA
"Observer" to have the progress dialog listen to the file copier for
progress events - this stops the file copier having to actually know
anything about a progress dialog). Make reporting of progress generic
(e.g. by programming to an ProgressListener interface that you create,
or similar).]]