Not receiving KeyEvents... or any events for that matter.

I have a very simple program so far; only a Component and a JFrame (to hold the component for testing purposes).

Component code is somewhat as follows:import java.awt.*;

import java.awt.event.*;

publicclass Boardextends Componentimplements KeyListener, Runnable

{

public Board(int width,int height)

{

setSize(width, height);

setVisible(true);

addKeyListener(this);

gameStarted =false;

}

publicvoid keyPressed(KeyEvent evt)

{

System.out.println("Key pressed.");

}

publicvoid keyReleased(KeyEvent evt)

{

}

publicvoid keyTyped(KeyEvent evt){System.out.println("Key typed.");}

publicvoid paint(Graphics g)

{

//some simple code

//just draws three rectangles and a circle, not very process intensive

}

publicvoid run()

{

while(true)

{

repaint();

try

{

Thread.sleep(20);

}

catch(InterruptedException e)

{

e.printStackTrace();

}

}

}

}

Testerpublicstaticvoid main(String args[])

{

Board b =new Board(300, 200);

JFrame test =new JFrame();

test.setSize(350, 250);

test.getContentPane().add(b);

test.setVisible(true);

//Thread boardThread = new Thread(b);

//boardThread.start();

//I commented the above out in case of some thread deadlocking occuring

}

The thing is, I click in the middle of the JFrame, where I clearly see what my paint code was supposed to draw, but when I type keys, I get no response from the console that something has occured.

Any ideas?

[3529 byte] By [RATiXa] at [2007-10-2 6:44:49]
# 1
Override isFocusable in Board
tjacobs01a at 2007-7-16 13:53:20 > top of Java-index,Desktop,Core GUI APIs...