This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Swing / AWT / SWT and the fly likes Serious issue: NumberFormat String Parse int problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Serious issue: NumberFormat String Parse int problem" Watch "Serious issue: NumberFormat String Parse int problem" New topic
Author

Serious issue: NumberFormat String Parse int problem

john price
Ranch Hand

Joined: Feb 24, 2011
Posts: 495

So i have two JFormattedTextFields, and later in the code two parseInts. On the JFormattedTextFields, I have a NumberFormat. The only issue I have with my code is when you try to enter a number above 999, the system prints out an error. I looked at it and found it was because of the "," (comma) that NumberFormat automatically does. Is there any way around this?
Thanks,
cc11rocks
EDIT: Code will be provided on request.


“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” (Mosher's Law of Software Engineering)
“If debugging is the process of removing bugs, then programming must be the process of putting them in.” (Edsger Dijkstra)
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19651
    
  18

JFormattedTextField has method getValue() that returns the value according to the format. This will definitely return a Number, but it may be a Double or Long. Regardless, you can call its intValue() method.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
john price
Ranch Hand

Joined: Feb 24, 2011
Posts: 495

Sorry I haven't replied. Was busy finishing school projects, hw, and such. Anyway, I'm not quite sure how to do what you suggested. I changed the line:

to:

and I'm coming up with the same results. I was thinking about changing all my code to the setValue(); and all that, but it would take too long. Do i have to do something like?:

Here is my code for Risk.java:

Thanks,
cc11rocks
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19651
    
  18

john price wrote:Do i have to do something like?:

Not quite; stupid and yummy are JFormattedTextFields so have no intValue() method. I meant this:
john price
Ranch Hand

Joined: Feb 24, 2011
Posts: 495

Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19651
    
  18

Compare your parentheses to mine, and see why your code doesn't work.
john price
Ranch Hand

Joined: Feb 24, 2011
Posts: 495

Thanks. You have cleaned up the comma problem but a new one has arisen. Could I make a post to have people help clean up my code? I'm not sure what I should have in my code anymore, because I think I can get rid of a lot. I just want to make sure it's allowed here. If my code was "cleaned up", I would be able to better asses the issue.
Thank you very much,
cc11rocks
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Serious issue: NumberFormat String Parse int problem
 
Similar Threads
NumberFormat question
Cannot find symbol, method getKeyChar()
How to use Locale ?
Setting unveven intervals in JFreechart
converting a numeric value...