Forum Stats

  • 3,852,844 Users
  • 2,264,142 Discussions


new simple behavior--I think I'm doing everything right

843799 Member Posts: 49,999
edited Jun 13, 2010 5:43PM in Java 3D
So I add this behavior to my scene graph, and I think I'm doing everything right, and the processStimulus just doesn't get called.

I think I have all the pitfalls covered:
scheduling bounds set;
added to the graph;
wakeup condition created;
wakeupon called in both initialize() and processStimulus()...

Can anyone look at my code and tell me what I'm missing?

I add the object:
        KeyBehavior keyBehavior = new KeyBehavior(locatableCallback); 
        keyBehavior.setSchedulingBounds(new BoundingSphere(new Point3d(0, 0, 0), 
this is the behavior code:
public class KeyBehavior extends Behavior {

    private static int deleteKey;
    private WakeupOnAWTEvent condition;
    private HashMap<Integer, KeyListener> map = new HashMap<Integer, KeyListener>();
    private InstrumentManager manager;
    public KeyBehavior(KnowsSelected knows) {
        manager= InstrumentManager.getInstance();
        if (Util.isMac()){
            deleteKey = KeyEvent.VK_BACK_SPACE;
        } else {
            deleteKey = KeyEvent.VK_DELETE;
        map.put(deleteKey, new DeleteListener(knows));

    public void initialize() {
        condition = new WakeupOnAWTEvent( KeyEvent.KEY_RELEASED );

    public void processStimulus(Enumeration criteria) {
        System.out.println("got here 1");
        if (manager.isEditMode()){
            System.out.println("got here 2");
            KeyEvent kevt = (KeyEvent) ((WakeupOnAWTEvent)criteria.nextElement()).getAWTEvent()[0];
            int kevtcode = kevt.getKeyCode();
            System.out.print("key event code "+ kevtcode + " == delete "+ deleteKey+"?");
            if (map.containsKey(kevtcode)){



  • 843799
    843799 Member Posts: 49,999
    edited Jun 13, 2010 5:43PM
    I would suggest putting the whole thing in a while loop:

    while(criteria.hasMoreElements()) {
    //all the rest of the processStimulus code

    If there isn't a while loop, you are only getting the first element of the enumeration.

    Edited by: trozamon on Jun 13, 2010 5:42 PM
This discussion has been closed.