Contents / Previous / Next


User Input Event Listeners


public class AwtFrameJogl extends Frame
      implements GLEventListener
{
    private void AwtFrameJogl() {
    
        ....

      // UserEventListener is tied to this canvas.
      UserEventMediator listener = new UserEventMediator
 	( this, inputDevice, view, light, canvas );
      canvas.addKeyListener( listener );
      canvas.addMouseListener( listener );
      canvas.addMouseMotionListener( listener );

	....
    }    
    ...
}

public class UserEventMediator implements 
KeyListener, MouseListener, MouseMotionListener 
{

  public UserEventMediator
  ( JOGLbase base, 
    InputDevice inputDevice,
    View view, 
    Light light, 
    GLCanvas canvas ) 
    {
      this.base  = base;
      this.inputDevice  = inputDevice;
      this.view   = view;
      this.light  = light;
      this.canvas = canvas;
    }

  public void keyPressed( KeyEvent e ) 
    {
        ...

	if (e.getKeyCode() == KeyEvent.VK_UP) {
	  view.moveFwd();
	}
	...

	//redisplay();
    }

  // Redisplay must be called if no animator is used.
  // Hence when the display is not updated regularly,
  // but an update should be triggered on some event.
  private void redisplay()
    {
      canvas.display();
    }
}