Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

NX: book a contractor and GUI

 
Rick Lu
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,
Now I am working on GUI. One problem confused me. When the user tries to book a contractor, the program will show a "Waiting" messagebox until the database finishes this action, then the messagebox hides automatically. Is it a good design?
The problem is that I cannot do this in Java. When the messagebox shows, everything freezes there (sounds it waits in EventQueue Thread???). No any database operation can be done in the back end, even with multithreads. Here is the code:

Any suggestion or any other way to do this? Please give me some idea...
Rick
Regards.
 
Philippe Maquet
Bartender
Posts: 1872
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Rick,
What about a simple status bar message and perhaps changing the mouse cursor in a "wait" cursor while operation is performing ?
Best,
Phil.
 
Rick Lu
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HI Philippe,
That's a good solution.
But is there any way to show the message in dialog, do the backend work, then automatically hide the dialog?
What is interesting there is that when Java popup a dialog (where sould I do it? in method actionPerformed or another thread???), the EventQueue thread just wait there, am I right? In which case, I have to create another thread for backend work?
And, how can I hide the dialog later? Any suggestion?
Rick
Regards.
 
Philippe Maquet
Bartender
Posts: 1872
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Rick,
I don't know how achieve what you are trying to do. But do you still need it BTW ?
Think of the fact that it's highly probable that displaying your "please wait" dialog will take much more time than performing the operation the use is waiting for ...
Best,
Phil.
 
Rick Lu
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Thanks for you reply, Phil. Yeah, you are right. The status bar is a quite smart solution. I am going to work on this.
The "waiting " dialog won't show in my final submission. But I still want to know whether we can do this way in Java. The EventQueue sounds so trick to me. I think this function should be very common in real applications, right?
Rick
Regards.
 
Filip Moens
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rick,
I used a class extending JWindow to show a "Busy screen".
As the last line of the constructor I did a setVisible(true).
After that I call a method to update the db and after returning from this call, I do a busyWindow.setVisible(false).
It works fine.
 
Rick Lu
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Filip,
Thanks for your solution. This is also something I should learn.

I used a class extending JWindow to show a "Busy screen".
As the last line of the constructor I did a setVisible(true).
After that I call a method to update the db and after returning from this call, I do a busyWindow.setVisible(false).

Can you please tell me where your constructor and busyWindow.setVisible(false) are called? In the method of actionPerformed (after click the "book" button) or in another spawned thread? Regards.
Rick
 
Filip Moens
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To make things a bit clear, I use the MVC pattern in the GUI.
In the view, there is a method bookRecord() which calls a method bookRecord() in the controller.
Before the call to the controller method, I do something like BusyWindow busyWindow = new BusyWindow("Searching", this); where this is the view window. It is passed as a parameter so that I can nicely center the BusyWindow over the view window.
Then, I call controller.findAll();
And after that I do busyWindow.setVisible(false);
I use actions instead of implementing actionPerformed directly in the view class, but you can do the same thing in the actionPerformed method.
Hope this helps.
 
Rick Lu
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Your solution definitively helps me. I am not familiar with action although now I am trying to. To my understanding, when you "click" the "book" button, something like BusyWindow should show.
However, you still need to implment actionPerformed in the Action class, right? Is that true that you call " BusyWindow busyWindow = new BusyWindow("Searching", this)" in the actionPerformed method of "book" button's action? As I know, if you setVisible() any frame, dialog in actionPerformed (which is actually in the thread EventQueue), the whole GUI will freeze.
So, I am curious whether you did call these methods in actionPerformed (whichever actionPerformed method) or in another spawn thread.
Thanks.
Rick
 
Filip Moens
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rick,
from actionPerformed in the acion class, I call a method in the view window which calls the constructor for the BusyWindow.
Actually, it does not matter where you call it: the BusyWindow extends JWindow and calling the setVisible method does NOT block the current thread. So there is no need to create another thread.
 
Rick Lu
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you. Understand it now.
 
Rick Lu
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Filip,

the BusyWindow extends JWindow and calling the setVisible method does NOT block the current thread. So there is no need to create another thread.

I just tried this solution and found a small problem. Because the BusyWindow extends the JWindow (not JDialog), this new window is a "non-model". In which case, you can focus on the other window, like the Main Window (or owner of BusyWindow).
Have you ever solve this problem? If we make the dialog be "model", GUI freeze.
Rick
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic