Hi all,

a testcase to show a problem using KeyEvents (and swing):

Canvas3D gets brought to front if the app is containing
a behavior that is listening to KeyEvents. This happens
when the mouse pointer enters  the screen area of Canvas3D
the first time, even if no MouseEvents are registered.
This will happen under awt or swing.
Also the app doesn't recognize keyboard inputs, you first
have to click into the canvas. This only happens under swing.
Keep in mind that no MouseEvents are registered.
The latter point is very annoying, as the user cannot start
keyboard actions but first has to klick into the canvas.
I hope future releases of Java3D will have a better collaboration
with Swing or vice versa.
------------------------------code_starts_here------------------------------
-----

import java.awt.event.*;
import com.sun.j3d.utils.geometry.ColorCube;
import com.sun.j3d.utils.universe.*;
import javax.media.j3d.*;
import javax.vecmath.*;
import javax.swing.*;
import java.util.*;

public class KeyEventTestCase extends JFrame
{
        //this contains code from HelloUniverse
  public BranchGroup createSceneGraph()
  {
                BranchGroup objRoot = new BranchGroup();
                objRoot.addChild(new ColorCube(0.4));
                TestBehavior bhv = new TestBehavior();
                bhv.setSchedulingBounds(new BoundingSphere(new Point3d(),
1000));
                objRoot.addChild(bhv);
          objRoot.compile();
                return objRoot;
  }

        public KeyEventTestCase()
        {
                Canvas3D c = new Canvas3D(null);
                getContentPane().add("Center", c);
                BranchGroup scene = createSceneGraph();
                SimpleUniverse u = new SimpleUniverse(c);
                u.getViewingPlatform().setNominalViewingTransform();
                u.addBranchGraph(scene);
        }

        public static void main(String[] args)
        {
                KeyEventTestCase test = new KeyEventTestCase();
                test.setBounds(10,10,256,256);
                test.setVisible(true);
        }

        class TestBehavior extends Behavior
        {
                WakeupCondition condition;
                public void initialize()
                {
                        condition = new WakeupOr(new WakeupCriterion[]
                                {       new
WakeupOnAWTEvent(KeyEvent.KEY_PRESSED),
                                        new
WakeupOnAWTEvent(KeyEvent.KEY_RELEASED),

                                });
                        wakeupOn(condition);

                }

                public void processStimulus(Enumeration e)
                {
                        System.out.println("do nothing");
                        wakeupOn(condition);

                }
        }
}
----------------------------------------------------------------------------
-------



Gernot Veith
[EMAIL PROTECTED]
http://www.janet.de

===========================================================================
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