LinuxQuestions.org
Go Job Hunting at the LQ Job Marketplace
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 07-03-2001, 02:48 PM   #1
mAineAc
Member
 
Registered: Nov 2000
Location: Hermon, ME
Distribution: slackware
Posts: 201

Rep: Reputation: 30
Question java programming


I am trying to get an applet to recognize if the input is a legal integer. I got it so that it will go to the program and do what it is supposed to do but it won't give a message if it is not a number. This is my code:

public void test() throws NumberFormatException {
if (testNumberField.getText() != null) {
PrimeTest();
}
else {
answer.setText("this is not a number!");
}
}


what am I doing wrong?

mAineAc
 
Old 07-04-2001, 09:10 AM   #2
cubed
LQ Newbie
 
Registered: May 2001
Location: Tokyo, Japan
Distribution: Red Hat 7.0, 7.1
Posts: 29

Rep: Reputation: 15
Hello mAineAc.

Firstly I'm probably newer to java than you but a few things ocurred to me when I saw this.

Here's some things to try:

Isn't an exception best dealt with using something like:

Code:
try {
       while (testNumberField.getText()!=null) {
        PrimeTest();
      }
} catch (NumberFormatException e) {
      System.out.println("This is not a number!"); // or answer.setText etc.
      }
Another thought - can you perhaps test for NaN ? (Don't know if that can be done but it's the first place I'd look)

This might have helped sorry if it hasn't.
 
Old 07-04-2001, 09:31 AM   #3
mAineAc
Member
 
Registered: Nov 2000
Location: Hermon, ME
Distribution: slackware
Posts: 201

Original Poster
Rep: Reputation: 30
thank you that is just what i was looking for. I am pretty new to java.

mAineAc
 
Old 07-06-2001, 09:42 AM   #4
cubed
LQ Newbie
 
Registered: May 2001
Location: Tokyo, Japan
Distribution: Red Hat 7.0, 7.1
Posts: 29

Rep: Reputation: 15
Smile

BTW, I just peeked at my CD reference (Java Power Reference from O'Reilly - highly recommended) and it does offer the following:
Code:
public static boolean java.lang.Double.isNaN(double v);

public static boolean java.lang.Float.isNaN(float v);
So in the brackets you put your number type and it'll return true or false if it's Not a Number.

Glad to be of help, mAineAc.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Java Programming: Java Runtime Environment not found when trying to compile murbz Linux - Software 2 03-26-2009 03:04 AM
Java Programming with KDevelop? Corallis Linux - Newbie 5 03-10-2006 05:57 PM
java support and programming with java sharapchi Slackware 8 11-14-2005 05:47 PM
java programming asahlot Programming 3 10-13-2005 10:30 AM
java programming ksd Programming 7 10-15-2003 06:29 PM


All times are GMT -5. The time now is 06:25 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration