Forums Register Login

Checking the characters

+Pie Number of slices to send: Send
Hi,
I wanted to validate the field so that it must not accept the characters like / - ? : <>{}. + - .
How can i do this with applet awt components.
Thanks for u'r help in advance
uday
+Pie Number of slices to send: Send
Java has KeyEvent & KeyAdapter functions that let you detect key strokes, you can simply write your own key adapter class extends KeyAdapter, and override the keyPress method. In that function, you check KeyEvent.getKeyCode(). Hope I explained clearly.
Frank
+Pie Number of slices to send: Send
Hi Uday,
In case you didn't understand Frank's explanation here is some code.

Enjoy,
Manfred.
+Pie Number of slices to send: Send
Frank,
Do u mean like this i need to follow,
import java.awt.event.*;
class KeyCheck extends KeyAdapter
{
public void keyPressed (KeyEvent event)
{
if (event.getKeyCode() == KeyEvent.VK_SLASH)
System.out.println("Slash was pressed");
}
}

then to call
TextField text = new TextField(30);
KeyCheck ck = new KeyCheck();
text.addKeyListener (ck);
then ck.keyPressed();// to call
Hope i am correct!! if so pls correct me

cheers
uday
+Pie Number of slices to send: Send
Frank,
Do u mean like this i need to follow,
import java.awt.event.*;
class KeyCheck extends KeyAdapter
{
public void keyPressed (KeyEvent event)
{
if (event.getKeyCode() == KeyEvent.VK_SLASH)
System.out.println("Slash was pressed");
}
}

then to call
TextField text = new TextField(30);
KeyCheck ck = new KeyCheck();
text.addKeyListener (ck);
then ck.keyPressed();// to call
Hope i am correct!! if so pls correct me

cheers
uday
+Pie Number of slices to send: Send
Thanks Manfrid and Frank!!
I could able to get the Trap the characters worked

Cheers
uday
Now I am super curious what sports would be like if we allowed drugs and tiny ads.
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 745 times.
Similar Threads
Limit JTextField number of characters
3d software
Scott Adams' depiction of IIT grads
max length of doGet() request supported by browser
Rest Response adding extra characters
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 29, 2024 04:28:39.