Click here to Skip to main content
15,887,746 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'm studying J2ME and I have a problem in capturing key status in class GameCanvas.
When I write my own class, which extends from GameCanvas class, I want to know which key is pressed at a moment.
But I can use keyStates() method but I can't use keyPressed() method.
I search on the Internet and some people said that the problem is caused of my constructor, so I changed my constructor. First, I used statement super(false); and then I used super(true);. Unfortunately, both cases seem to be useless, keyPressed() method still can't get the key information.
Hope someone will give me a solution.
P/s: My compiler is Eclipse 3.5 Galileo
Posted

You can have a look at this project, J2ME for beginners[^], it uses the keyPressed() and it works as expected.

Hope this helps,
Fredrik
 
Share this answer
 
I saw the article you gave carefully. In this example, the author used Canvas class and the code did well.
Now I'm using a GameCanvas class. GameCanvas extends from Canvas class, so everyone hopes keyPressed() still works. But, in my situation, this method doesn't work.
Anywway, thanks alot Fredrik
 
Share this answer
 
Sorry, gave you the wrong link, try this[^] instead. It's part 2 of the tutorial and it uses the GameCanvas with working keyPressed.

Apologies for sending the wrong link,
Fredrik
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900