Hi !
I believe that you hate me in this community ;D so whats the problem ?? Pratically I don’t know why the keylistener doesn’t work …
public GameView(){
//System.out.println("hey");
JFrame container= new JFrame("Loderunner");
JPanel panel= (JPanel) container.getContentPane();
panel.setPreferredSize(new Dimension(460,460));
panel.setMinimumSize(new Dimension(460,460));
panel.setLayout(null);
setBounds(0,0,460,460);
panel.add(this);
setIgnoreRepaint(true);
requestFocus();
addKeyListener(new KeyHandle());
container.pack();
container.setVisible(true);
container.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
createBufferStrategy(2);
strategy=getBufferStrategy();
loadLevel("level.txt");
}
This class is in GameView class
private class KeyHandle extends KeyAdapter {
public void KeyPressed(KeyEvent e){
System.out.println("hey");
if(e.getKeyCode()==KeyEvent.VK_LEFT){
System.out.println("hey");
runner.setRunning(true);
runner.setDX(1);
}
}
public void KeyReleased(KeyEvent e){
if(e.getKeyCode()==KeyEvent.VK_LEFT){
runner.setRunning(false);
runner.setDX(0);
}
}
}
}
I put some System.out.println but if i press left they print nothing , so i believe that the problem is in the costructor …