944,123 Members | Top Members by Rank

Ad:
  • Java Discussion Thread
  • Unsolved
  • Views: 1621
  • Java RSS
Apr 20th, 2005
0

Listeners

Expand Post »
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.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Light Poster
Black Knight is offline Offline
25 posts
since Mar 2005
Apr 20th, 2005
0

Re: Listeners

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.
Reputation Points: 92
Solved Threads: 51
Practically a Posting Shark
Phaelax is offline Offline
856 posts
since Mar 2004
Apr 20th, 2005
0

Re: Listeners

why don't you make a method which assigns true instead of just declaring loggedIn = true;

in other words
Java Syntax (Toggle Plain Text)
  1. loggedIn = setTrue();
  2.  
  3. public boolean setTrue()
  4. {
  5. //do some stuff when the variable is set true here!
  6. return true;
  7. }
Reputation Points: 13
Solved Threads: 4
Posting Whiz
paradox814 is offline Offline
351 posts
since Oct 2004
Apr 20th, 2005
0

Re: Listeners

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!
Reputation Points: 113
Solved Threads: 19
Postaholic
server_crash is offline Offline
2,108 posts
since Jun 2004
Apr 21st, 2005
0

Re: Listeners

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.
Reputation Points: 10
Solved Threads: 0
Light Poster
Black Knight is offline Offline
25 posts
since Mar 2005
Apr 21st, 2005
0

Re: Listeners

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.
Reputation Points: 13
Solved Threads: 4
Posting Whiz
paradox814 is offline Offline
351 posts
since Oct 2004
Apr 21st, 2005
0

Re: Listeners

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.
Team Colleague
Reputation Points: 1658
Solved Threads: 331
duckman
jwenting is offline Offline
7,719 posts
since Nov 2004
Apr 21st, 2005
0

Re: Listeners

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
Reputation Points: 10
Solved Threads: 0
Light Poster
Black Knight is offline Offline
25 posts
since Mar 2005
Apr 21st, 2005
0

Re: Listeners

I think i will look further into propertychangeevents
Reputation Points: 10
Solved Threads: 0
Light Poster
Black Knight is offline Offline
25 posts
since Mar 2005

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Java Forum Timeline: Parameters order
Next Thread in Java Forum Timeline: Exception NoClassDefFoundError





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC