Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

key listener

Posted on 1997-04-03
2
Medium Priority
?
150 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 150 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
Suggested Courses

971 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