Solved

key listener

Posted on 1997-04-03
2
141 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
2 Comments
 
LVL 1

Accepted Solution

by:
fadl earned 50 total points
Comment Utility
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
Comment Utility
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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…

728 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now