Boa Noite
estou desenvolvendo um jogo com swing e awt
O jogo em si eu ja consegui fazer não consigo fazer umas das funcionalidas que deveria o pause
Eu consigo pausar o jogo em si só que aundo eu volto o jogo perco a isntancia do key listener que controla o jogo
como poderia recuperar isso para depois que der o pause e mandar despausar ele volte a funcionar
Eis o codigo
ONDE ELE INICIA O KEYLISTNER
public Game() {
//this.panel = (JPanel) container.getContentPane();
this.panel.setPreferredSize(new Dimension(800,600));
this.container.add(panel);
panel.setLayout(new GridBagLayout());
setBounds(0,0,800,600);
panel.add(this);
System.out.println("filha de "+this.panel.getParent());
// Tell AWT not to bother repainting our canvas since we're
// going to do that our self in accelerated mode
this.container.setIgnoreRepaint(true);
// finally make the window visible
container.pack();
//container.setResizable(false);
container.setVisible(true);
// add a listener to respond to the user closing the window. If they
// do we'd like to exit the game
container.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
// add a key input system (defined below) to our canvas
// so we can respond to key pressed
this.container.getContentPane().addKeyListener(new KeyInputHandler());
// request the focus so key events come to us
this.container.getContentPane().requestFocus();
// create the buffering strategy which will allow AWT
// to manage our accelerated graphics
createBufferStrategy(2);
strategy = getBufferStrategy();
// initialise the entities in our game so there's something
// to see at startup
initEntities();
}
ONDE EU PRECIDO RECUPERAR ELE DE NOVO
public void pause() {
this.panel.setPreferredSize(new Dimension(800,600));
this.container.add(panel);
this.panel.setLayout(new GridBagLayout());
this.setBounds(0,0,800,600);
this.panel.add(this);
this.container.setIgnoreRepaint(true);
this.container.pack();
this.container.setVisible(true);
this.container.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
this.container.getContentPane().addKeyListener(new KeyInputHandler());
this.container.getContentPane().requestFocus();
this.createBufferStrategy(2);
this.strategy = getBufferStrategy();
this.gameLoop();
}
desde ja obrigado