"For key pressed and key released events, the getKeyCode method returns the event's keyCode. For key typed events, the getKeyCode method always returns VK_UNDEFINED."
change to keyPressed/Released and it should work OK
Stuart Gray
Ranch Hand
Joined: Apr 21, 2005
Posts: 410
posted
0
Yep, that is where I was heading. I figured the methods must be being called, so probably the if statements were not evaluating to true. Didn't have the API docs handy though.
r bal sometimes it can be very useful to add a few extra println calls to your code to determine what is happening. By putting a println at the top of the method, you can tell whether or not the method is being called at all. Its a very useful debugging technique sometimes.
[ May 13, 2005: Message edited by: Stuart Gray ]
r bal
Greenhorn
Joined: Mar 31, 2005
Posts: 6
posted
0
thanks for all the advice....
but unfortunately, the methods aren't even being read. Ie. I put println statements in all the 3 methods before the if statements, and still nothing happened.
i guess i'll keep on with the trial and error.
Michael Dunn
Ranch Hand
Joined: Jun 09, 2003
Posts: 4632
posted
0
it could be what you're adding the listener to.
here's what I think is a reconstruction of your description, it works OK adding it directly to the frame, and also to the panel, if the indicated line is set.
r bal
Greenhorn
Joined: Mar 31, 2005
Posts: 6
posted
0
The option you had that was commented out...was the one I orginally had.
I tried the other option using the JPanel, but still no success.
I have tried absolutely everything I can think of.
This has me stumped.
Stuart Gray
Ranch Hand
Joined: Apr 21, 2005
Posts: 410
posted
0
A thought - when you call addKeyListener(myboard), has myboard already been initialised at this point? The reason I ask is because if it is null the addKeyListener won't work - but no error message will be thrown either! Basically you should have a line like this somewhere before you try to add the KeyListener:
r bal
Greenhorn
Joined: Mar 31, 2005
Posts: 6
posted
0
yes, i have that line of code before I add the keyListener.
I just can't figure it out...everything I need seems to be there and in the right place.
Is there any other way to go about adding keyListeners using different methods or different classes?
Stuart Gray
Ranch Hand
Joined: Apr 21, 2005
Posts: 410
posted
0
Maybe you can post the full code if it is relatively short?