• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Can't put the result in a text box

 
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.


 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Swing? Spring? JSF? Struts? Other?
 
Charles Angemeyer
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry, Swing.
Thank you.
 
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Marshal
Posts: 79179
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Really sorry guys. Saw my own error and fixed it.
thanks.
 
Paul Clapham
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.)
 
An elephant? An actual elephant. Into the apartment. How is the floor still here. Hold this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic