punaiz jdevien fou, j'ai regardé plein de tutoriaux sur lé keylistener et ca ne marche pas.
Voici mon code
public class Chenille extends JFrame implements KeyListener
{
JPanel pan;
static int Xmax = 500;
static int Ymax = 500;
Tete x;
Anneau[] corps;
public Chenille(int largeur,int hauteur,int rayon,int nbAnneau)
{
this.x = new Tete(250,250,rayon,90);
this.pan = new JPanel();
pan.addKeyListener(this);
this.getContentPane().add(pan);
this.pan.setBackground(Color.WHITE);
this.corps = new Anneau[nbAnneau];
int i=0;
for(i=0;i<this.corps.length;i++)
{
this.corps[i] = new Anneau(this.x.abs -(i+1)*rayon,this.x.ord,rayon);
}
}
public void keyPressed(KeyEvent evt)
{
int caract = evt.getKeyCode();
if(caract == 28)
{
System.out.println("bas");
}
else if(caract == 26)
{
System.out.println("haut");
}
else if(caract == 27)
{
System.out.println("droite");
}
else if(caract == 25)
{
System.out.println("gauche");
}
else
{
System.out.println("fork");
}
}
public void keyTyped(KeyEvent evt)
{
System.out.println("ici");
}
public void keyReleased(KeyEvent evt)
{
System.out.println("ici2");
}
}
dc voilà qd j'execute tout mon prog , et que j'appui sur lé touche du
clavier il ne se passe rien, qq'un peut t'il me dire pk svp ?
mici d'avance