I want to make a TextBox class which only accepts integers.
How can i do it?
Thanx all.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
I’ll assume that you mean Java Swing and desktop.
Use a JTextField class; you need not create a new class. You may “wanna”, but I’m arguing that there’s no need to do it. The behavior you need doesn’t reside in the JTextField class. Extending an existing class should mean different behavior. You can get what you want by adding the appropriate Listener.
Creating a new class may turn out to be harmful. At best, it increases your maintenance burden; at worst, you’ll get it wrong.
Write a Listener to ensure that only integers are allowed.
http://download.oracle.com/javase/tutorial/uiswing/components/textfield.html