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.

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.

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

in other words

loggedIn = setTrue();

public boolean setTrue()
{
     //do some stuff when the variable is set true here!
     return true;
}

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!

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.

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.

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.

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

I think i will look further into propertychangeevents

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.