Add a comment. Active Oldest Votes. Comments I'm not sure if your comment about using Nimbus with a reference to Java 6 , when you are clearly using Java 8 already really belongs there Java 8, and Swing vs AWT both are related by the understanding of the language features you have here You are using Swing-based UIs, but interestingly you are coupling them with AWT's mechanism of event-handling.
Improve this answer. Regarding the comments, the ones you referenced were auto-generated, and I should have removed them from the post. I also hadn't thought to include methods inside the enum; I keep forgetting I can assign it its own methods just like any other class. Is it normal to do logic calculations inside an enum though? This would really cut down on code, but it doesn't quite sit right with me semantically.
Aren't enums just meant to be a limiter of a type's domain and nothing more? I understand "helper" methods, such as converters from ints to an enum value, or changing the name like I mentioned before, but program logic seem to be a totally separate entity.
This might just be the novice coming out of me, so if this is normal, I'll certainly embrace it! Thanks again! If there are certain calculations that seem 'right' to belong to a class, then I don't see issues incorporating it into the enum too. Thanks for the tip!! Show 1 more comment. Eric G Eric G 6 6 bronze badges. I've only been able to find how to add regular listener methods.
Sign up or log in Sign up using Google. Sign up using Facebook. Sign up using Email and Password. Post as a guest Name. Create a free Team What is Teams? Learn more. Temperature converter program Ask Question. Asked 5 years, 4 months ago. Active 5 years, 4 months ago.
Viewed 2k times. Improve this question. Pakbert Pakbert 83 1 1 silver badge 7 7 bronze badges. Add a comment. Active Oldest Votes. Resource Management To avoid resource leaks, it is usually good to close IO classes like java. Error handling At least write an error handling mechanism, even a general one. Improve this answer. Sign up or log in Sign up using Google. You ought not to be calculating anything inside a frame class. You ought to have a temperature converter class which does the calculations.
This is how you ought to have developed your app 1: Create a Temperature class, or a TemperatureConverter class. If you use a TemperatureConverter class, that will work completely differently. Winston Gutkowski wrote: Lee Sigauke wrote: Thanks that did the trick. Lee Sigauke wrote:. I'd like my program to calculate the temperature rather than having predefined methods doing it for me. Campbell Ritchie wrote: Lee Sigauke wrote:.
Thank you for your help, I've learnt more than I though. Forum: Beginning Java. How can I get my temperature converter program to display negative numbers. Lee Sigauke. Optional 'thank-you' note:. I wrote this code and when I convert small values of Fahrenheit to Celsius it gives me zero instead of the negative number, I looked for a sample program online and there isn't anything special about it so what am I doing wrong?
My code is still not complete yet so please forgive the imperfections. My Code : import javax. JFrame; import javax. JButton; import java. ActionListener; import java. ActionEvent; import java.
0コメント