Obter Um keyListner

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

Esse código aí é baseado no livro do Dave Brackeen?

Não entendi pq vc recria o seu BufferStrategy ao pausar o game. A pausa é geralmente um estado do jogo. Teste numa variável se está pausado, e pule o processamento da lógica enquanto estiver assim. No máximo, faça o processamento de alguma tela de pause.

Isso mesmo desse livro mesmo

obrigado pela dica vou tentar aqui

O livro do Brackeen é ótimo. Um dos melhores para jogos 2D. Só cuidado com a parte de threads, pois a dele está bem desatualizada. A partir do Java 5, já existem classes de pool de threads no pacote java.util.concurrent, mais eficientes que a classe que ele propõe.

obrigado funcionou mesmo eu passei horas pensando e era um solução tão simples obrigado

Pois é, se gostou de implementar jogo, quando puder, dá uma passada lá no meu portal:
http://www.pontov.com.br/site