Skip to main content

Key Listeners Wont Work

Please note these forums are being decommissioned and use the new and improved forums at
No replies
Joined: 2010-12-29

package Gears;<br />
import java.awt.event.KeyEvent;<br />
import java.awt.event.KeyListener;<br />
public class Gears extends Core implements KeyListener {<br />
public static void main(String[] args){<br />
Gears gear = new Gears();<br />;     }<br />
public void run(){<br />
window.addKeyListener(this);<br />
}<br />
@Override<br />
public void keyPressed(KeyEvent arg0) {<br />
    System.out.println("Pressed");<br />
}<br />
@Override<br />
public void keyReleased(KeyEvent arg0) {<br />
    System.out.println("released");<br />
}<br />
@Override<br />
public void keyTyped(KeyEvent arg0) {<br />
    System.out.println("Typed");<br />
}<br />

Ok so when I press release or anything while my window is open it doesnt print any of those messages. Window is made inside the core if thats the problem. I also setFocusable and Requestfocus in the core for the window.

Any help is appreciated idk what im doing wrong.