Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Can't put the result in a text box

 
Charles Angemeyer
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm trying to put the result of a calculation in my text box three but the program throws an error stating that the method setText is not applicable to a double.
Can someone please tell me how I could fix this?
Thank you.


 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65223
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Swing? Spring? JSF? Struts? Other?
 
Charles Angemeyer
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry, Swing.
Thank you.
 
Paul Clapham
Sheriff
Posts: 21416
33
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


So tf1 is a JTextField or something like that? (It helps if you tell us what's actually happening instead of using general terms like "text box".) Anyway, assuming that's the case, then the error message (which you should have posted rather than giving a general description) is telling you that it doesn't have a setText(double) method. However you know that it does have a setText(String) method, it appears. So there's only a small gap to bridge there. Namely, you just have to convert your double to a String and then pass that String value to the setText method.
 
Campbell Ritchie
Sheriff
Pie
Posts: 50235
79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Charles Angemeyer wrote:Sorry, Swing.
Thank you.
So I shall move this discussion there:- to the Batmobile Swing Forum!
 
Charles Angemeyer
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you.
I took your suggestion and it works for the division button (first one) but not the next three.
When I type a couple of ints in the first two text boxes and then click the buttons for +, -, or * nothing happens. No error messages, just nothing appears in the third text box as I would like it to.
The division works fine however.
Can you give me a hint what might be going wrong? Many thanks.
Complete code follows:

 
Charles Angemeyer
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Really sorry guys. Saw my own error and fixed it.
thanks.
 
Paul Clapham
Sheriff
Posts: 21416
33
Eclipse IDE Firefox Browser MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
All fixed then? Good to hear it.

(I think that's called the "Rubber Duck" effect -- you keep a rubber duck on your desk and when you run into a problem, you explain it to the rubber duck. Half the time you realize what the answer is while you're doing the explaining. I never had a rubber duck but my boss was sometimes a pretty good substitute for one.)
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic