• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Swing and Thread nightmare. Please help.

 
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

This has been eating me in and out. I will give the code here you can try it out. Sorry it might be a little long/boring.



I first draw a GUI with a button. This is done by 'GUIDrawer'. I start it as a thread so that EDT will not be blocked. And when you click the 'TEST' button, I want to pop up a frome with YES and NO, and according to user click, the string 'password' will be changed.

The problem is, I want to check the value of 'password' 'after' the user had clicked the button. So I have put in wait()/notify() statements (Thanks to Norm).

But the problem is, no matter what I do or how many threads I start, I cannot get the YES and NO buttons on the passwordFrame. It gives me the frame but not the buttons. If I take off the wait() statement I get the buttons. I'm a litle baffled as to why it gives me the frame but I do not getthe buttons? GUITester is the class associated with the TEST button. Which calls the GetPassword thread and wait(). If you comment the monitor.wait() statement in the GUITester class you can see that the passwordFrame gives the buttons. Otherwise no buttons (only frame).

Any help will be greatly appreciated. Thank you.

[ August 02, 2008: Message edited by: Maduranga Liyanage ]

[ August 02, 2008: Message edited by: Maduranga Liyanage ]
[ August 02, 2008: Message edited by: Maduranga Liyanage ]
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This seems a strange (and unnecessary) way to use threads.

I start it as a thread so that EDT will not be blocked.


I don't understand this. Why would the event dispatching thread by blocked?
 
Maduranga Liyanage
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Ulf Dittmer:
This seems a strange (and unnecessary) way to use threads.

I don't understand this. Why would the event dispatching thread by blocked?



Thank Ulf.
Could you please let me know what I am doing wrong and why I am not getting the buttons and 'only' the frame?

I 'guessed' wait() blocks the EDT otherwise I cant think of a better reason why I get the frame(with buttons) when there is no monitor.wait() and only the frame when there is monitor.wait().

Thanks mate.
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I don't know what the problem is. To me, there is little point in trying to get this code to work when it seems such a strange way to implement this.

Again: Why are you using threads at all?
 
Maduranga Liyanage
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Because if I don't use a thread and wait() on the main, it blocks the JFrame.. atleast thats what I think becasue until I notify() the GUI does not update.

What do you suggest the best way is when I need to 'wait' for user input before proceeding?

Thank you.
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, if you didn't use threads, there would be no need to call notify() or wait() or any of the other thread-related methods. So I don't see what could block.

The usual way to trigger an action would be to add an action listener to whatever button the user has to click after he has entered the password.
 
Rancher
Posts: 5008
38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here's a working version of your code. One problem was doing things on the EDT in the Test button listener. Another was having more than one object: monitor. I forget the others I found.
 
Maduranga Liyanage
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Ulf Dittmer:
Well, if you didn't use threads, there would be no need to call notify() or wait() or any of the other thread-related methods. So I don't see what could block.

The usual way to trigger an action would be to add an action listener to whatever button the user has to click after he has entered the password.



Thanks Ulf.
I'll see if I can work with that. I have put an actionlistener to the button the user if clicking after the password. The problem is the button isnt showing up in the frame when I have wait().
But still dosnt understand why the GUI update is blocking by when I have a wait().
[ August 02, 2008: Message edited by: Maduranga Liyanage ]
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic