Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

key listener

Posted on 1997-04-03
2
Medium Priority
?
148 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 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: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering 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

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…
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
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

715 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