This week's book giveaway is in the OCPJP forum.
We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line!
See this thread for details.
The moose likes Java in General and the fly likes Ho could I erase the text field contents as soon as the user presses the CTRL key Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Ho could I erase the text field contents as soon as the user presses the CTRL key" Watch "Ho could I erase the text field contents as soon as the user presses the CTRL key" New topic
Author

Ho could I erase the text field contents as soon as the user presses the CTRL key

kei hosima
Greenhorn

Joined: Feb 23, 2003
Posts: 13
Hello.
I hope someone could help me.
How could I erase a text field's contents as soon as the user presses the CTRL key while the text field has focus?
"data" is a properly instantiated TextField object with class-wide scope and the current object as its registered KeyListener.
public void keyTyped (KeyEvent e) {
TextField t = data.getText();
t.clearRect (0, 0, data.getWidth(), data.getHeight());
}
the above code won't work.
I would really appreciate your help.
Thanks in advance.
Michael Morris
Ranch Hand

Joined: Jan 30, 2002
Posts: 3451
Hi kei,
Try something like this:


Michael Morris


Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius - and a lot of courage - to move in the opposite direction. - Ernst F. Schumacher
kei hosima
Greenhorn

Joined: Feb 23, 2003
Posts: 13
Michael
Thank you so much for your help.
I'll try your code.
thank you!
kei
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Ho could I erase the text field contents as soon as the user presses the CTRL key