another prb in java
i have no idea how to make sure if whatever the user is an integer or not. i wan the user to enter integers only in a text field. how can i make sure he does?
I think there is some direct method in Java for what you asked, but one easy workaround would be to do this:
Pass the string that you get from the user (strUser) to the following method:
If the string is not a decimal integer, NumberFormateException is thrown. Catch this exception and return a message telling the user to enter valid integers.
forgive me for asking you this, but you do know that by text field, i mean TextField txt = new TextField(25) and not the text field that you see when u'r using joptionpane.showinputdialog to enter an integer. right?
What difference does it make? a string is a string wherever you get it from. Use the paramString() method to get the string, then parse the string to an integer as Atlas suggested. Do you know how to use a try/catch block? You should do the parsing inside a try block, and then catch a NumberFormatException in the catch block. If you don't know how to use them just ask and we will explain
many thanx. ya i know how to use them. they're used so that you'll catch the exception and make sure ur prg keeps on running rather than having to recompile it again after checking for errors like the default handler does. i'll get to it once am done with my other work. thanx
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL