behavior and swing question

Hi!

Is it possible to control the WakeupOnElapsedTime behavior using a swing button. I basically want to control the start and stop of my animation.

Thanks

Sure, thats possible. You just cannot add() it to a Canvas3D. You need to put it aside.

Can u plz explain a bit more. I tried calling it from a separate method. Wasn’t effective

I’m afraid I don’t exactly understand what your problem is?

Is it more the Swing button or is it about modifying a wakeup behavior?

What you need to do is:

  1. Create the Behavior that you want to start/stop.
    You will need to add WakeOnAWTEvent criterion in addition to the WakeOnElapsedFrames using a WakeOr criterion.

  2. Expose a reference to the behavior somewhere so that you can pass it to the Swing button

  3. Create the Swing button and put it on a Swing container somewhere.

  4. You will need a specialized MouseListener for the button (like an anonymous MouseAdapter). This Listener should have the reference to the Java3D behavior passed to it. When the Button is pressed, send an AWTEvent to the behavior and have the behavior handle it.

Hi!

Thanks for the help. The method you have described would probably work. With the behavior I was having the flickering problem. I have used the Swing Timer instead, there is no or very less flickering, since I just wanted to a time delay so that after a certain interval the next line from the animation file is executed. It works ok. Swing Timer has listerners which allows me to start and stop the animation.

SwingTimers… sounds strange, but if it works…