KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I have tried to use the example shown here but java showing error message of "AttributeSet cannot be resolved to a type" That is why I am trying to use another method of allowing only digits: txtUsername.addKeyListener(new MyKeyListener()); public class MyKeyListener extends KeyAdapter{ public void keyPressed(KeyEvent ke){ System.out.println("Key pressed code = "+ke.getKeyCode()); if (ke.getKeyCode()>=48 && ke.getKeyCode()<=57) return true; else return false; } } But of course it is not working because keyPressed method is void . So, what to do in order to print only digits in textfield?
Tags (comma-separated)
Save Edits
Cancel