I have a keylistener attached to my frame in java, I can detect keystrokes when I press any key, however a strange thing happens. My game is a minesweeper, I have a restart button that basically clears the board and overwrites it. Strange, when I press the button with the mouse, everything clears up fine, and the board remains in memory, but the keylistener stops working. Even a stranger, I have a jmenuitem that basically does an automatic button click. So this is like restartbutton.doclick ()
if I click on jmenuitem to restart it, reboots, clears everything, and the keylistener function still functions. I can even see that a button is pressed. Any ideas why this could be happening?
thanks
this is attached to my main frame. This is a listener that stops working after clicking a button.
frame.addKeyListener(new KeyListener(){ public void keyReleased(KeyEvent e){ } public void keyPressed(KeyEvent e){ System.out.println("hey"); int keycode = e.getKeyCode(); if(e.isControlDown() & keycode==KeyEvent.VK_C){ balh blah balh } } public void keyTyped(KeyEvent e){ } });
source share