aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes Can't put the result in a text box Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Can Watch "Can New topic
Author

Can't put the result in a text box

Charles Angemeyer
Greenhorn

Joined: Dec 18, 2012
Posts: 22
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

Joined: Jan 10, 2002
Posts: 61653
    
  67

Swing? Spring? JSF? Struts? Other?


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Charles Angemeyer
Greenhorn

Joined: Dec 18, 2012
Posts: 22
Sorry, Swing.
Thank you.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18907
    
    8



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

Joined: Oct 13, 2005
Posts: 39834
    
  28
Charles Angemeyer wrote:Sorry, Swing.
Thank you.
So I shall move this discussion there:- to the Batmobile Swing Forum!
Charles Angemeyer
Greenhorn

Joined: Dec 18, 2012
Posts: 22
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

Joined: Dec 18, 2012
Posts: 22
Really sorry guys. Saw my own error and fixed it.
thanks.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18907
    
    8

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.)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Can't put the result in a text box