This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Temperature Converter Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Temperature Converter" Watch "Temperature Converter" New topic
Author

Temperature Converter

David Coello
Greenhorn

Joined: Jun 05, 2012
Posts: 22
Hello forum members,

I am a new java developer. I have been working on a Converter from Farenheit to Celsius with the push of a button. I programmed it under those specs, but I would like to program that same button to convert back to celsius. I appreciate your comments, basically if a button can perform 2 actions, convert from Fahrenheit to Celsius and Celsius to Farenheit.


Thank you.

David

Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30138
    
150

Yes, the same button can do two things. You'd need an instance variable to remember which state the button is in so you know which label to display and which action to perform.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
check which textfield is empty, via .equals(""), ensuring both are not empty,
then convert the non-empty for display in the empty
 
Don't get me started about those stupid light bulbs.
 
subject: Temperature Converter
 
Similar Threads
Incompatiable variable types
Need HELP Temperature Conversion
Button not working in applet
Which is the best practice?
non-static method init() cannot be referenced from a static context