Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Validating a TextField in an Applet

Posted on 2002-03-21
4
Medium Priority
?
299 Views
Last Modified: 2010-05-18
Hi everyone!
This is an easy question:
How can I validate a TextField to be sure that it contains only numbers? If it has something else I want to Open a Message Box informing the problem and return the focus to it.
This must be done in an Applet.

Thanks for any help in Advance!

Regards,
MRXZ
0
Comment
Question by:mrxz
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 86

Expert Comment

by:CEHJ
ID: 6886232
Add a KeyListener to the TextField and disallow anything that's not part of a number
0
 
LVL 18

Expert Comment

by:bobbit31
ID: 6886293
> Add a KeyListener to the TextField and disallow anything that's not part of a number

they'll still be able to paste text into the textbox... to be sure, you can check the contents when they submit (click the button or whatever)

try {
   int textVal;
   textVal = Integer.parseInt("<text in textbox>");
} catch (NumberFormatException nfe) {
   // not an int so do what you need to do
}
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 6886303
That's true bobbit31!
0
 
LVL 5

Accepted Solution

by:
Calron earned 30 total points
ID: 6894111
The way to solve this is to write a Document for the textfield. The concept is explained nicely in the java tutorial:

http://java.sun.com/docs/books/tutorial/uiswing/components/textfield.html#validation

0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
Suggested Courses

610 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question