public SpaceGame(int width, int height){
...
addKeyListener(new MyKeyListener());
// Keyboard input requires the listening component to have the focus.
setFocusable(true);
new Thread(this).start();
...
public static void main(String [] args){
...
frame.add(g);
// This should be last for proper/complete initialization.
frame.setVisible(true);