File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes Validating bookseats JTextField  contents Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "Validating bookseats JTextField  contents" Watch "Validating bookseats JTextField  contents" New topic

Validating bookseats JTextField contents

Lisa Foster
Ranch Hand

Joined: Feb 28, 2001
Posts: 116
For Example,
In my gui the user has a field to input the number of seats he or she wishes to purchase I will compare the available seats that are availble first then how do I validate that the input data is a number and not a string or garbage???
I already have a BookSeat button with action event.

Thanks Lisa
Ken Zrobok

Joined: Mar 08, 2001
Posts: 20
There are many ways to approach this. The core Java 2 vol 1 book has a section on consuming key events (ch. Event Handling), so as to disregard any key events that don't correlate to numbers
Or you can parse the trimmed input from the textbox and catch a NumberFormatException when the input is processed.

Ken Zrobok<BR>Java Developer/Trainer<BR>SCJP SCJD SCWCD
I agree. Here's the link:
subject: Validating bookseats JTextField contents
It's not a secret anymore!