Click to See Complete Forum and Search --> : Threading the GUI


winston2020
April 4th, 2008, 03:49 PM
Could someone please tell me how I can do this: I have a GUI class, and I have a class that does all the calculations for the program (happens to be a file decryptor). I want the GUI to start the decryption, and update a JProgressBar. Which I know how to do, HOWEVER, it causes the processing to take a very, very long time. I believe if I put the processing class in a different thread than the GUI, it will work better (is that correct?). But I don't know how to have the two threads communicate (specifically transfer the total progress from the decrypting class to the gui).

Any help?

Deliverance
April 4th, 2008, 04:30 PM
Read up on the Singleton design pattern. You can return the running instance of a particular class, and have that class have a method which is exposed onto it which takes a value for your progress.

Londbrok
April 4th, 2008, 06:15 PM
We have not seen any code. It is possible that you are doing things marveloussly wrong. Different thread for the pcroeccsing calss (whatever that means) can prove a solution, or not. What is clear, is that you should, at least have the calculations totally separe from GUI. Singleton pattern is one solution, or not, but evidently you need provide more information as to how you currently approach this issue. What your calculations are etc. From what you told us, it seems to me, that your GUI updates are diretctly dependant on your calculations, and the calculations are commenced within the same process... and that is not good. But cannot say, having seen no code.

Could be wrong in all these assumptions... but have not seen any code :)