Results 1 to 4 of 4
- 02-14-2012, 09:36 PM #1
Member
- Join Date
- Mar 2011
- Posts
- 34
- Rep Power
- 0
Why is my KeyAdapter acting weird? - please don't move to awt/swing
Hello
Sorry about the title, but my last post got moved and since hasn't had any attention, and yes, I'm new to Java so I feel this is the correct forum to post on. Anyway, onto the issue.
When I run the code and press a key I get cA twice. What's going on there?Java Code:private class Watcher extends KeyAdapter @Override public void keyPressed(KeyEvent k) { Character c = k.getKeyChar(); char cA = c.toUpperCase(c); System.out.println(cA); }
Thanks in advance.
- 02-14-2012, 10:05 PM #2
Re: Why is my KeyAdapter acting weird? - please don't move to awt/swing
Are you saying your method is being called two times?
There are can be several reasons for that:
How many instances of the class with the method are there?
How many times has an instance of that class been added as a key listener?
- 02-14-2012, 10:22 PM #3
Member
- Join Date
- Mar 2011
- Posts
- 34
- Rep Power
- 0
Re: Why is my KeyAdapter acting weird? - please don't move to awt/swing
Hi Norm
Answers as follows
There is only one instance of the class with the method.
There are 20 times the instance of that class has been added. This is part of my problem(hence the title of the thread). I need to add a key listener to the GUI but don't know where to add it. The only options I have are the buttons or the menu. Everything else is private in the parent class. I think this may be where the issue lies. My menu watcher is fine and my button watcher is fine but the key listener is weird (I can't change the parent class).
Thanks
- 02-14-2012, 10:27 PM #4
Re: Why is my KeyAdapter acting weird? - please don't move to awt/swing
Please see http://www.java-forums.org/content/113-forum-rules.html
That's not your choice. There's a reason we have separate sections for disparate topics.please don't move to awt/swing
I'm moving this thread to AWT/Swing and closing it. Any additional post for the same question may lead to a ban. Please continue the discussion in your original thread, in AWT/Swing.Why do they call it rush hour when nothing moves? - Robin Williams
Similar Threads
-
actionPerformed acting strangely
By Fortu in forum New To JavaReplies: 18Last Post: 04-10-2011, 04:07 AM -
Can you help with this class? Boolean variables acting weird
By jazzermonty in forum New To JavaReplies: 6Last Post: 01-14-2011, 04:08 PM -
Problem using KeyAdapter to get keyboard input
By DerekRaimann in forum New To JavaReplies: 0Last Post: 12-20-2010, 04:10 AM -
Acting Java as if it's C problem
By reis3k in forum New To JavaReplies: 13Last Post: 10-18-2010, 09:10 AM -
KeyAdapter won't fire
By billq in forum New To JavaReplies: 5Last Post: 04-14-2010, 02:37 AM


LinkBack URL
About LinkBacks


Bookmarks