KeyEvent locking up with mouse press?

I am new to JOGL and trying to learn how it all works. I am making decent progress, but I’m having an issue with mouse clicks stopping my KeyEvents from firing off at all. I’m not entirely sure it is a JOGL issue, but similar code was working fine before I converted from Java2D to JOGL. Does the Canvas or FPSAnimator require a different type of event handling for key and mouse presses? Any help would be appreciated.

Here’s the code:

import java.awt.*;
import java.awt.event.*;

import javax.media.opengl.*;
import javax.media.opengl.glu.*;

import com.sun.opengl.util.FPSAnimator;

public class GameEngine extends Frame implements GLEventListener, KeyListener
  {
  private final GLCanvas canvas = new GLCanvas();
  private final GLU glu = new GLU();
  private FPSAnimator animator = new FPSAnimator(canvas, 60, true);
//  private Map gameMap = new Map();

  public GameEngine(String title, int width, int height)
    {
    canvas.addGLEventListener(this);
    add(canvas);
    this.setResizable(false);
    this.setUndecorated(true);
    this.setIgnoreRepaint(true);
    this.setFocusable(true);
    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    GraphicsDevice gd = ge.getDefaultScreenDevice();
    gd.setFullScreenWindow(this);
    
    animator.start();

    addWindowListener(new WindowAdapter()
      {
        public void windowClosing(WindowEvent e)
          {
          new Thread(new Runnable()
            {
              public void run()
                {
                animator.stop();
                System.exit(0);
                }
            }).start();
          }
      });
    this.addKeyListener(this);
//    this.addMouseListener(this);
    setVisible(true);
    }

  public void display(GLAutoDrawable drawable)
    {
    final GL gl = drawable.getGL();

    gl.glMatrixMode(GL.GL_MODELVIEW);
    gl.glLoadIdentity();
    gl.glClear(GL.GL_COLOR_BUFFER_BIT);

    
    //gameMap.draw(0, 0, gl);    
    }

  public void init(GLAutoDrawable drawable)
    {
    final GL gl = drawable.getGL();

    gl.setSwapInterval(1);

    gl.glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
    gl.glColor3f(0.0f, 0.0f, 0.0f);
    gl.glPointSize(1.0f);

    gl.glMatrixMode(GL.GL_PROJECTION);
    gl.glLoadIdentity();
    glu.gluOrtho2D(0.0, getWidth(), 0.0, getHeight());
    }


  public void displayChanged(GLAutoDrawable arg0, boolean arg1, boolean arg2)
    {
    }

  public void reshape(GLAutoDrawable drawable, int i, int x, int width,
      int height)
    {
    }
  
  public void mousePressed(MouseEvent e)
    {
    }
  public void mouseClicked(MouseEvent e)
    {
    }
  public void mouseEntered(MouseEvent e)
    {
    }
  public void mouseExited(MouseEvent e)
    {
    }
  public void mouseReleased(MouseEvent e)
    {
    }
  public void keyPressed(KeyEvent e)
    {
    int keyCode = e.getKeyCode();
    if ((keyCode == KeyEvent.VK_ESCAPE) || (keyCode == KeyEvent.VK_Q)
        || (keyCode == KeyEvent.VK_END)
        || ((keyCode == KeyEvent.VK_C) && e.isControlDown()))
      {
      animator.stop();
      System.exit(0);

      // setRunning(false);
      }
    }
  public void keyReleased(KeyEvent e)
    {
    }
  public void keyTyped(KeyEvent e)
    {
    }  
  }

KeyEvents work normally and quit the program unless you click the mouse at all before pressing one of the quit combos.

You are probably facing a focus issue here, because your canvas gains focus when you click, so your frame gets unfocused and won’t get keyevents anymore. Try setting canvas.setFocusable(false).

That fixed it. Thank you very much!

Ok, now I am trying to add my mouse events and they aren’t working. I implemented MouseListener and added one to my frame just like the KeyListener. I already had the required methods overloaded. I put test code in each method to see if they work and none of them are detecting clicks. Is my canvas getting in the way again? Should I add the key and mouse listeners to the canvas instead? What is the standard here?