Results 1 to 2 of 2
- 12-11-2010, 07:29 PM #1Member
- Join Date
- Dec 2010
- Rep Power
Adding a KeyListener to a JFrame with buttons.
Hey, I haven't been learning java very long so this may be really easy.
We have a project and it involves inputting and encrypting a message. I don't want to add a keylistener to a JTextbox or anything similar as then the message I input is plainly viewable. I was hoping to be able to simply type when the frame is up and encode the text I type.
This won't seem to work though in the window I want it to work in. It does work when i add the keylistener to an otherwise empty frame. But on the frame with buttons on it it won't work.
Any help? Need to see the code?
For a key listener to work, the component that holds it must have focus, and this is the reason why you're having problems when there are buttons on your JFrame. One solution is to make your listening component focusable and then give it the focus. Another solution is to use key binding.
Myself, though, I like seeing what I type to be sure that there are no mistakes, and then converting the document, with an exception for passwords.
- By Rhez in forum New To JavaReplies: 2Last Post: 08-05-2010, 06:19 AM
- By kumarv75 in forum CLDC and MIDPReplies: 0Last Post: 06-22-2010, 07:10 AM
- By Nemo1959 in forum New To JavaReplies: 8Last Post: 09-15-2008, 06:57 PM
- By Java Tip in forum Java TipReplies: 0Last Post: 12-17-2007, 10:46 AM