Results 1 to 10 of 10
- 02-09-2012, 10:56 AM #1
Looks Simple But I Cant Get It Right. Help!
I was doing code for a simple calculator when i came across this problem..
i have a JTextField named textfield_1
i used the code : textfield_1.setText(textfield_1.getText()+"9");
output : 239 //23 was already present in the textfield
the problem was when i used this code : textfield_1.setText(textfield_1.getText()+".");
output : .239
//Here is the problem //the decimal point should come after the number ie. 239.
if i again use the 1st code ie. textfield_1.setText(textfield_1.getText()+"9");
output : 239.9 //So mathematically there are no errors, but the display of 2nd code is the problem
Can Any1 tell me the reason for that??
And how to correct that display??Last edited by Kuttappu; 02-09-2012 at 12:54 PM.
- 02-09-2012, 11:09 AM #2
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,606
- Blog Entries
- 7
- Rep Power
- 17
Re: Looks Simple But I Cant Get It Right. Help!
Maybe it's just a visibility problem; try to change the dot "." to a "X" for testing purposes.
kind regards,
JosWhen people rob a bank they get a penalty; when banks rob people they get a bonus.
- 02-09-2012, 12:03 PM #3
- 02-09-2012, 12:32 PM #4
- 02-09-2012, 12:34 PM #5
- 02-09-2012, 12:46 PM #6
Moderator
- Join Date
- Apr 2009
- Posts
- 10,484
- Rep Power
- 16
Re: Looks Simple But I Cant Get It Right. Help!
That's not a great improvement...What's wrong with simply bolding it?
- 02-09-2012, 12:55 PM #7
- 02-09-2012, 01:02 PM #8
Re: Looks Simple But I Cant Get It Right. Help!
Moderator, should this be moved to Advanced? Though it looks simple many, including a teacher of mine couldn't answer this.
- 02-09-2012, 01:54 PM #9
Moderator
- Join Date
- Apr 2009
- Posts
- 10,484
- Rep Power
- 16
Re: Looks Simple But I Cant Get It Right. Help!
Print out the value of textField.getText() before appending.
Then append the "." into a holding String and print that out.
Then pass that holding String to the setText() method.
Actually, prior to doing that, print out the value of getText() after doing your current code, so you can see what the code is actually holding.
- 02-09-2012, 09:53 PM #10
Re: Looks Simple But I Cant Get It Right. Help!
Nothing advanced about it, but the question is related to Swing so I'll move it to a more appropriate forum.
To get better help sooner, post a SSCCE (Short, Self Contained, Compilable and Executable) example that demonstrates the problem. And note that the first 'S' stands for short.
dbWhy do they call it rush hour when nothing moves? - Robin Williams
Similar Threads
-
Simple program, simple problem
By taymilll in forum New To JavaReplies: 12Last Post: 06-20-2011, 05:12 AM -
30 line simple gui, simple error, need help
By cc11rocks in forum New To JavaReplies: 6Last Post: 02-05-2011, 08:33 PM -
New simple application using a simple database
By webbusiness23 in forum New To JavaReplies: 9Last Post: 08-03-2009, 02:55 AM -
Help with a very simple method for a very simple beginner.
By cakeman in forum New To JavaReplies: 2Last Post: 05-04-2008, 05:27 PM


LinkBack URL
About LinkBacks
Reply With Quote
ok ok.. i changed the color..

Bookmarks