Thanks to all your reply, I will change my design to using thread then, cuz it sounds much easier for me to program in threads this way.  :)

Andy

Florin Herinean wrote:
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
===========================================================================
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".

Reply via email to