import java.awt.AWTEvent;import java.awt.event.*;import java.util.Enumeration;import javax.media.j3d.*;import javax.vecmath.*;import javax.swing.JRadioButton;import com.sun.j3d.utils.universe.*;public class HMDCoexistToTBBehavior extends Behavior {  private WakeupCondition keyCriterion;  double distance, rotation;  PhysicalEnvironment environment;   JRadioButton rb;    public HMDCoexistToTBBehavior(PhysicalEnvironment environment, JRadioButton rb) {    this.environment = environment;    this.rb = rb;    System.out.println("HMDCoexistToTBBehavior constructor");  }  public void initialize() {        WakeupCriterion[] keyEvents = new WakeupCriterion[2];    keyEvents[0] = new WakeupOnAWTEvent( KeyEvent.KEY_PRESSED );    keyEvents[1] = new WakeupOnAWTEvent( KeyEvent.KEY_RELEASED );    keyCriterion = new WakeupOr( keyEvents );    wakeupOn( keyCriterion );    System.out.println("initialize complete");  }  public void processStimulus( Enumeration criteria ) {     WakeupCriterion wakeup;    AWTEvent[] event;    while( criteria.hasMoreElements() ) {      wakeup = (WakeupCriterion) criteria.nextElement();      if( !(wakeup instanceof WakeupOnAWTEvent) )        continue;      event = ((WakeupOnAWTEvent)wakeup).getAWTEvent();      for( int i = 0; i < event.length; i++ ) {        if( event[i].getID() == KeyEvent.KEY_PRESSED & rb.isSelected()==true)        {          processKeyEvent((KeyEvent)event[i]);        }      }    }    wakeupOn( keyCriterion );  }  protected void processKeyEvent(KeyEvent event) {    int keycode = event.getKeyCode();    Transform3D ctotb = new Transform3D();    environment.getCoexistenceToTrackerBase(ctotb);        Transform3D tchange = new Transform3D();    tchange.setIdentity();    //if cntl rotate + - if not cntl rotate +     if (event.isAltDown()) {        distance = -1;        rotation = -1*Math.PI/72;     }     else {        distance = 1;        rotation = Math.PI/72;            }        //if shift --translate; else rotate            if (event.isShiftDown()) {         if(keycode == KeyEvent.VK_X) {        System.out.println("translating X for CoexistenceToTrackerBase");        tchange.setTranslation(new Vector3d(distance, 0.0, 0.0));      }       else if(keycode == KeyEvent.VK_Y) {        System.out.println("rotating around Y for CoexistenceToTrackerBase");        tchange.setTranslation(new Vector3d(0.0, distance, 0.0));      }        else if(keycode == KeyEvent.VK_Z) {        System.out.println("rotating around Z for CoexistenceToTrackerBase");        tchange.setTranslation(new Vector3d(0.0, 0.0, distance));      }    }    else {      if(keycode == KeyEvent.VK_X) {         System.out.println("rotating around X for CoexistenceToTrackerBase");         tchange.rotX(rotation);      }       else if(keycode == KeyEvent.VK_Y) {         System.out.println("rotating around Y for CoexistenceToTrackerBase");        tchange.rotY(rotation);      }        else if(keycode == KeyEvent.VK_Z) {         System.out.println("rotating around Z for CoexistenceToTrackerBase");         tchange.rotZ(rotation);      }   }           ctotb.mul(tchange);       environment.setCoexistenceToTrackerBase(ctotb);  }}