| | |
Listeners
![]() |
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.
why don't you make a method which assigns true instead of just declaring loggedIn = true;
in other words
in other words
Java Syntax (Toggle Plain Text)
loggedIn = setTrue(); public boolean setTrue() { //do some stuff when the variable is set true here! return true; }
•
•
Join Date: Jun 2004
Posts: 2,108
Reputation:
Solved Threads: 18
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!
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.
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.
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
![]() |
Similar Threads
- Audio Website Testimonial (Promotion and Marketing Plans)
- Macromedia Releases MX (Graphics and Multimedia)
- Radio/TV/Print & Web Advertsing to 2 million weekly just $24.99/Month! (Ad Space for Sale)
- Java Internal frames (Java)
- I have a question about functions (Java)
- Action listeners (Java)
- Linux Audio Streaming (live!) using Ices and Icecast (*nix Software)
- More svchost.exe problems (Windows NT / 2000 / XP)
Other Threads in the Java Forum
- Previous Thread: Parameters order
- Next Thread: Exception NoClassDefFoundError
| Thread Tools | Search this Thread |
android api applet application apps array arrays automation awt bidirectional binary birt bluetooth businessintelligence busy_handler(null) card chat class classes client code collision columns component constructor database designadrawingapplicationusingjavajslider draw eclipse error errors eventlistener exception expand fractal game givemetehcodez graphics gui guidancer html ide image inetaddress input integer intellij j2me java javafx javamicroeditionuseofmotionsensor javaprojects jme jni jpanel jtree julia linux list loop machine map method methods mobile mobiledevelopmentcreatejar myaggfun netbeans newbie oracle physics plazmic print problem program programming project recursion scanner server set sharepoint smart sms smsspam sort sortedmaps sql string subclass support swing textfield threads tree trolltech unlimited utility webservices windows






