Problems with KEYListener,

Hello I´m very new to jogel
i´ve tried to move an geometric objekt with Pressed Keys, but it does not work. That´s what i´ve done:

import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;

import net.java.games.jogl.*;
//import net.java.games.jogl.util.GLUT;

public class MoveTest_view implements GLEventListener, KeyListener
{

public static float x=0;
public void init(GLDrawable drawable)
{
	GL gl = drawable.getGL();
	gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);

	gl.glMatrixMode(GL.GL_PROJECTION);
	gl.glLoadIdentity();
	gl.glFrustum(-5, 5, -5, 5, 2, 12.0);
	gl.glMatrixMode(GL.GL_MODELVIEW);
	
	drawable.addKeyListener(this);
	
	gl.glLoadIdentity();
}

public void display(GLDrawable drawable)
{	
	GL gl = drawable.getGL();
		
	gl.glClear(GL.GL_COLOR_BUFFER_BIT);
	
	gl.glTranslatef (x, 0, 0);
	
	gl.glPushMatrix();
	gl.glTranslatef (0.0f, 0.0f, -3.0f);		
	gl.glBegin(GL.GL_POLYGON);
		gl.glVertex3f(-0.5f, 0.35f, 0.0f); // links unten (x,y,z) koordinate
		gl.glVertex3f(0.5f, 0.35f, 0.0f);
		gl.glVertex3f(0.0f, 1.4f, 0.0f);
	gl.glEnd();
	gl.glPopMatrix();
}

public void reshape(GLDrawable drawable, int x, int y, int width, int height)
{}

public void displayChanged(GLDrawable drawable, boolean modeChanged, boolean deviceChanged)
{}

public void keyTyped(KeyEvent arg0) {}

public void keyPressed(KeyEvent arg0) 
{
	switch(arg0.getKeyCode())
	{
	case KeyEvent.VK_LEFT:  x=x-0.1f     ; break;
	case KeyEvent.VK_RIGHT: x=x+0.1f     ; break;
	}
}
public void keyReleased(KeyEvent arg0) {}	

}

Can someone tell me where my problem is?
Does Someone here knows a GOOD jogl Tutorial (somthing like NEHE´s but for Java).
Thank You

You probably need a call to repaint() in your keyPressed() method.

I´ve used the animater. I thought the animater recalls the display methode the whole time.
Thank you.

oh god, i got it,
i don´t know why , but you have to klick into the window with the triangle, befor you use the keys, the code is correct.

BTW, there’s a link to Pepijn Van Eeckhoudt’s NeHe ports to JOGL and other tutorials on the jogl-demos page.

But why do you have to click into the window before the application reacts on key-events ?
I had the same problem some time ago…

thx

Your canvas doesn’t have the “input focus.” You can get the canvas “the focus” bycalling Component.requestFocusInWindow(). Link to all you ever wanted to know about focus.