Being afraid of threads is pretty stupid. Threads are what makes things to happen smooth and to promptly react regardless of what else the computer is doing. If you're not using threads, then *everything* in your program will happen sequentialy, i.e. you won't be able to do 2 things simultaneous. Besides that, threads are as stable as anything. If you suppose that a thread may cease functioning, the same might apply to the main thread, the one with the loop. In case you didn't know, everything in java is based on threads. A running java program have at the same time, several threads running simultaneous, even if your program does nothing more than HelloWorld !
Now you're concrete example has a very simple solution: Your "do something" code is in a behavior attached to your scene. You register a mouse move listener with your canvas3d. You check in the listener the current position of the mouse, if it's in the desired area, you start the behavior (if not already started), and if it's out of the area you stop the behavior (if it's not already stopped). The behavior can have a wake criterion as elapsed time or elapsed frames, as you like. You're simply not interested in anything else. And your sistem will be much more responsive, since you're not eating cpu cycles siting in a tight loop. That way you won't explicitly create threads, although you're using at least three of them: the awt dispatcher thread to process the mouse events, the behavior thread which will execute the code inside of your behavior and the rendering thread which will render the image. Learn to think in terms of events: you create events, you react to events. Cheers, Florin -----Original Message----- From: Discussion list for Java 3D API [mailto:[EMAIL PROTECTED] Behalf Of Andy Sent: Mittwoch, 28. April 2004 15:37 To: [EMAIL PROTECTED] Subject: Re: [JAVA3D] Java3D and Mouse Listener question Thank you for replying. I need to check the mouse position constantly even it's not moving, for example, if I move my mouse to (25, 50) and stop moving, when the mouseMoved() method detected that it's inside it will keep doing something until this mouse is moving away from this area. Someone suggests me to use a thread to check constantly inside the method, and use the listener to stop it anytime the mouseMoved() method changes the position. Now what I don't wanna use is thread, I am thinking if it is possible for me to do it C/C++ way like this: Loop Check mouse position IF mouse position is in the area, do something ELSE do nothing End Loop Since I am worring about the thread that will make our program unreliable or unstable, therefore I rarely use thread. The main reason is that since I am trying to make a very simple RTS game, so if mouse moving thread is stop responding or a bit slow because of the CPU time or whatever, it will make the game not synchronized. If I use C/C++ way that dose not use fork, check everything in one flow, it gurantees the flow. Thus, do you have any idea that I can check the mouse position like the loop above without using thread? Since I tried having the mouseMoved() method loads another method that has a loop that checks the mouse position every iteration, but the mouseMoved() method cannot stop it even it changes the variable, I believe it's because of the loop takes highest priority. Thank you very much, I appreciate your help. Andy Florin Herinean wrote: >I don't understand why do you want to check the mouse position if the mouse >is not moving ??? It's obvious that the position is the last one where a >mouse move event was fired. If you really need to know the mouse position at >every moment, then just use the mouse move listener to store the position of >the event in some convenient place. Then from wherever you are, you can get >from there the current position. And don't forget to synchronize access to >the mouse position. > >Cheers, > >Florin > >-----Original Message----- >From: Discussion list for Java 3D API >[mailto:[EMAIL PROTECTED] Behalf Of Andy >Sent: Dienstag, 27. April 2004 20:12 >To: [EMAIL PROTECTED] >Subject: [JAVA3D] Java3D and Mouse Listener question > > >Hi all, > >I am currently have a program that has a cube, and a camera. I use >mouse event listener to check if the mouse moves to the edge of the >program, if yes, then it moves the camera. But if I move my mouse to >the edge and stop there, it just checks whenever the mouse moves or not, >otherwise, it doesn't know if the mouse pointer is on the edge or not. >Then is there any class or method that I can use to check mouse pointer >location every single second or loop? Thanks. > >Andy > >=========================================================================== >To unsubscribe, send email to [EMAIL PROTECTED] and include in the body >of the message "signoff JAVA3D-INTEREST". For general help, send email to >[EMAIL PROTECTED] and include in the body of the message "help". > >=========================================================================== >To unsubscribe, send email to [EMAIL PROTECTED] and include in the body >of the message "signoff JAVA3D-INTEREST". For general help, send email to >[EMAIL PROTECTED] and include in the body of the message "help". > > > =========================================================================== To unsubscribe, send email to [EMAIL PROTECTED] and include in the body of the message "signoff JAVA3D-INTEREST". For general help, send email to [EMAIL PROTECTED] and include in the body of the message "help". =========================================================================== To unsubscribe, send email to [EMAIL PROTECTED] and include in the body of the message "signoff JAVA3D-INTEREST". For general help, send email to [EMAIL PROTECTED] and include in the body of the message "help".