Solved

key listener

Posted on 1997-04-03
2
144 Views
Last Modified: 2010-04-16
When I run the following code, a is always 0 regardless of what key is pressed. It doesn't crash, so I assume the syntax is correct. I've tried every combination and permutation of the 1.1.1 options for keys (getKeyChar, getKeyText, etc) and nothing works. Any advice? Really, all I want to do is refresh the screen each time a key is pressed. The keyCode() is just for debugging.

addKeyListener (new KeyAdapter() {
public void keyTyped(KeyEvent e)
{
a=e.getKeyCode();
repaint();
}
});
0
Comment
Question by:rbixby
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 1

Accepted Solution

by:
fadl earned 50 total points
ID: 1219416
Are you sure you have registered the right object as a keyListener ?
If yes then you must include more source code it is
nearly impossible to say what's wrong by seeing on such a small
piece of code {:)
How was 'a' variable declared ?

0
 

Author Comment

by:rbixby
ID: 1219417
a is an int in this case, though when I was listening for a char, it was a char and when I was listening for text, it was a string.
I guess it's setting up the key listener that's confusing me. It sounds as if I need additional code to actually get key input. I'll read the chapters I have again and review some code I downloaded from javasoft yesterday. Maybe the answer is in there. If you have any more advice, I'm all ears.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.
Suggested Courses

751 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question