• Post Reply Bookmark Topic Watch Topic
  • New Topic

KeyAdapter class

 
Mohamad Samy
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have the following code by


but every time I compile I got an error: Can't find symbol KeyAdpater so, what is the problem
 
Campbell Ritchie
Marshal
Posts: 52555
119
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I presume you have made a spelling error somewhere. There is another spelling error in your code, which you would have picked up with the @Override annotation.
 
Mohamad Samy
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
believe me, I checked it many times but in vain. ignore that error because I had to make the hard way to implement the interface and override all the methods without the adapter class.
the code below is a typing program to simulate the keyboard but when I pressed any key it writes in the text area both the upper and lower case also how can I make the text area responds to the functional keys without writing
their strings in the text area

here is the code
 
Rob Spoor
Sheriff
Posts: 20819
68
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mohamad Samy wrote:

If you reorder your imports you'll see you're missing something:
 
Piet Souris
Rancher
Posts: 1631
36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mohamad Samy wrote:(...) how can I make the text area responds to the functional keys without writing
their strings in the text area (...)

Don't add the keyListener to your textarea. A Textarea already has an in-built keylistener, so that's
why you get two characters when you type into your textarea.

Instead, if I understand your code correctly, the idea is that the user must click on the buttons, making
the character involved to be added to the textarea. Am I right?
If so, set the textarea to uneditable (textarea.setEditable(false),
and put the keyListener to all your buttons. I'm not sure what a click on the BackSpace button
will do, whether it erases the last charater, or do something else. Keep us informed!

Greetings,
Piet
 
Mohamad Samy
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are totally right. I removed the line of appending the string on the textarea and get enough with the inbuilt listener of the text area as you said. And it gives me one case at time. But i don't know how to add listener to a button to make the functional key do its role if turned thetext area to uneditable.
 
Rob Camick
Ranch Hand
Posts: 2699
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are totally right. I removed the line of appending the string on the textarea and get enough with the inbuilt listener of the text area as you said


I told you to do that hours ago in your other posting: http://www.coderanch.com/t/624219/GUI/java/writing-keylistener
 
Mohamad Samy
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes you did. But i had no idea about this inbuilt listener f text area that is what i mean. Thanks
 
Mohamad Samy
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes you did but the conection was cut from the laptop and i had to log in from mobile later thanks.
 
Piet Souris
Rancher
Posts: 1631
36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Piet Souris wrote: (,,,)
If so, set the textarea to uneditable (textarea.setEditable(false),
and put the keyListener to all your buttons. I'm not sure what a click on the BackSpace button
will do, whether it erases the last charater, or do something else. Keep us informed!

(...)

Don't know what I was thinking here...
You must put an ActionListener to all your buttons, instead of a KeyListener. A KeyListener
on a button only works if that button has the so called 'input focus', which is hard to ensure
when working with so many buttons!

Therefore, to each button add an ActionListener (one AL for all buttons would do), and when
a button is clicked upon, add the corresponding character to the textarea. Still wondering
what happens when you click the BackSpace button, though...

Greetings,
Piet
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!