Using the mouse

When using a Java Frame to hold the JOGL GLCanvas, interaction with the frame, using the mouse, can be done in the usual way by using a Listener. The listener event handler class (the class which is to receive the events), must implement the MouseListener, MouseMotionListener interfaces. One of the nice things about Eclipse is that the moment you add these interfaces to the class it will ask you if you want to add the corresponding functions.
public class joglpbuffer implements 
GLEventListener,
MouseListener,
MouseMotionListener {

public void init(GLAutoDrawable drawable) {
drawable.addMouseListener(this);
drawable.addMouseMotionListener(this);
}
}

The event functions themselves are self explanatory. They are all passed a MouseEvent argument which can be used to determine the location of the mouse or the button that was just pressed.
  public void mouseClicked(MouseEvent e) {}
public void mouseEntered(MouseEvent e) {}
public void mouseExited(MouseEvent e) {}
public void mouseMoved(MouseEvent e) {}
public void mousePressed(MouseEvent e) {
prevMouseX = e.getX();
prevMouseY = e.getY();
if ((e.getModifiers() & e.BUTTON3_MASK) != 0) {
mouseRButtonDown = true;
}
}
public void mouseReleased(MouseEvent e) {
if ((e.getModifiers() & e.BUTTON3_MASK) != 0) {
mouseRButtonDown = false;
}
}
public void mouseDragged(MouseEvent e) {
int x = e.getX();
int y = e.getY();
}