Listeners

Reply

Join Date: Mar 2005
Posts: 25
Reputation: Black Knight is an unknown quantity at this point 
Solved Threads: 0
Black Knight's Avatar
Black Knight Black Knight is offline Offline
Light Poster

Listeners

 
0
  #1
Apr 20th, 2005
Is there anyway to listen to a bool value? I have a login window that has a loggedIn boolean value, I need to watch that value in the main thread so when it changes to true it returns to the main thread and loads up the rest of the program, i used to have it trailing through the program, ie, if you logged in the login listener would then start the main program but due to threading problems i am trying to keep it returning the the main thread to control it all. If there is another way i havent thought of that doesnt use listeners let me know, I dont really want to have to use a loop which checks it all the time.
Reply With Quote Quick reply to this message  
Join Date: Mar 2004
Posts: 763
Reputation: Phaelax is on a distinguished road 
Solved Threads: 38
Phaelax Phaelax is offline Offline
Master Poster

Re: Listeners

 
0
  #2
Apr 20th, 2005
I think you need to look at the Observer class. I'm not entirely sure how to use it, but it sounds like thats what you need.
Reply With Quote Quick reply to this message  
Join Date: Oct 2004
Posts: 348
Reputation: paradox814 is an unknown quantity at this point 
Solved Threads: 4
paradox814's Avatar
paradox814 paradox814 is offline Offline
Posting Whiz

Re: Listeners

 
0
  #3
Apr 20th, 2005
why don't you make a method which assigns true instead of just declaring loggedIn = true;

in other words
  1. loggedIn = setTrue();
  2.  
  3. public boolean setTrue()
  4. {
  5. //do some stuff when the variable is set true here!
  6. return true;
  7. }
Reply With Quote Quick reply to this message  
Join Date: Jun 2004
Posts: 2,108
Reputation: server_crash is on a distinguished road 
Solved Threads: 18
server_crash server_crash is offline Offline
Postaholic

Re: Listeners

 
0
  #4
Apr 20th, 2005
I don't think you would have to use loops to continously check to see if it's true. I think you could just use some simple if statements or something simple to check if it's true.

Paradox has a neat solution to it..Have a method that makes it true, and also can perform any other task you want if the boolean is true. If it were me, I would go that route. Nice solution Paradox!
Reply With Quote Quick reply to this message  
Join Date: Mar 2005
Posts: 25
Reputation: Black Knight is an unknown quantity at this point 
Solved Threads: 0
Black Knight's Avatar
Black Knight Black Knight is offline Offline
Light Poster

Re: Listeners

 
0
  #5
Apr 21st, 2005
i already have the set and get methods, the problem is the true bool is an attrib of the gui and you cant return values from a gui. so an if statement wouldnt work either, i need the main thread to watch the awt thread for the bool change and then shut down that gui and start another one. I think Phaelax was hitting nearer the mark with the observer class, I had looked at it but was playing with invokeandwait() thread method.
Reply With Quote Quick reply to this message  
Join Date: Oct 2004
Posts: 348
Reputation: paradox814 is an unknown quantity at this point 
Solved Threads: 4
paradox814's Avatar
paradox814 paradox814 is offline Offline
Posting Whiz

Re: Listeners

 
0
  #6
Apr 21st, 2005
ahhh... it's a gui component, well then just implement the appropiate listener. You should have said this from the beggining it's kind of hard to guess what you are doing. What component are you using? I will show you how to implement the appropiate listener if you do not know how to.
Reply With Quote Quick reply to this message  
Join Date: Nov 2004
Posts: 6,143
Reputation: jwenting is just really nice jwenting is just really nice jwenting is just really nice jwenting is just really nice 
Solved Threads: 212
Team Colleague
jwenting's Avatar
jwenting jwenting is offline Offline
duckman

Re: Listeners

 
0
  #7
Apr 21st, 2005
Your component can fire for example a PropertyChangedEvent and your other class register itself with the component as a PropertyChangeListener (or whatever it's called).

Needs a bit of code, but I'm sure most decent books and the Java tutorial have ample examples.
As people are clearly allowed to attack me but I'm not allowed to defend myself, I no longer post to this site.
Reply With Quote Quick reply to this message  
Join Date: Mar 2005
Posts: 25
Reputation: Black Knight is an unknown quantity at this point 
Solved Threads: 0
Black Knight's Avatar
Black Knight Black Knight is offline Offline
Light Poster

Re: Listeners

 
0
  #8
Apr 21st, 2005
well in i want the main thread to basically wath the gui it creates and as soon as the bool in the gui flips to true i want it to dispose of the log in window and open the main app window, i have tried to implement propertychangelisteners and changelisteners etc... to no avail, i did have it creating the main window through the login listener but i am trying to code it a different way now
Reply With Quote Quick reply to this message  
Join Date: Mar 2005
Posts: 25
Reputation: Black Knight is an unknown quantity at this point 
Solved Threads: 0
Black Knight's Avatar
Black Knight Black Knight is offline Offline
Light Poster

Re: Listeners

 
0
  #9
Apr 21st, 2005
I think i will look further into propertychangeevents
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the Java Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC