Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Serious issue: NumberFormat String Parse int problem

 
john price
Ranch Hand
Posts: 495
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Rob Spoor
Sheriff
Pie
Posts: 20511
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
john price
Ranch Hand
Posts: 495
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 20511
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 495
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
Rob Spoor
Sheriff
Pie
Posts: 20511
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Compare your parentheses to mine, and see why your code doesn't work.
 
john price
Ranch Hand
Posts: 495
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic