File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Swing / AWT / SWT and the fly likes Developing a temperature calculator with GUI Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Developing a temperature calculator with GUI" Watch "Developing a temperature calculator with GUI" New topic
Author

Developing a temperature calculator with GUI

Jeff Karr
Greenhorn

Joined: May 02, 2013
Posts: 10
I don't think it's a good idea for anyone learning a programming language to learn without some good ole fashion peer review so what I have here is an idea for a very small program I want to write but I'd like to work with others and get some input and ideas before I start. Question is, how would you START a project like this? this will technically be my first GUI program heres the layout I had in mind.

- a small text field that ask you to enter a value (the temperature in this case)
- a radio button that allows you to switch from Celsius to Fahrenheit and vice versa.
- a submit button, once you hit this it will run the calculations and display the results in a pop-up window.

So how would I go about doing this? Would each text field/button be a class in it's own right? and how would I go about combining the presentation with the actual calculation code? this has confused me a lot. How to use inheritance and extends with all this?

How would I make the GUI work and function with the underlying code if the GUI classes don't contain it? Do I borrow from another class?

any help is appreciated, regards...

-Jeff.
Neelesh Srinivasan
Greenhorn

Joined: Jan 23, 2013
Posts: 11
Jeff,
You must go through AWT and then Swing in order to design a GUI based application. Extends and Implements are an integral part of GUI Programming in Java. You need to implement Listeners in order to handle events generated by your application. For simplicity you can refer The Complete Reference Java by Herbert Schildt or Head First Java which will clear all your concepts on extends and implements and then switch over to AWT and Swing.

All the Best
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 9990
    
    7

Neelesh Srinivasan wrote:
You must go through AWT and then Swing in order to design a GUI based application.

No. You do not need to "go through" AWT. In fact you should not even consider AWT for any modern code.

Neelesh Srinivasan wrote:
Extends and Implements are an integral part of GUI Programming in Java

I would say they are an integral part of Java/OOP and not only GUI.

@Jeff
1) You will need a high level container (e.g. JFrame)
2) You will need a container with a proper layout to display the children. e.g. JPanel (with correct layout) to display the text field, radio button etc) Layout managers for containers are very important. Avoid null layout and explicitly setting bounds like a plague
3) Once you have the UI ready, you need to make it interact with the user. Swing relies on event delegation model.
4) It is a good idea to have an external helper class do the conversion for you. That way, it is easier to add to the existing functionality later on. e.g. Celsius <-> Kelvin

Since this is your first attempt at GUI, I would recommend you go through http://docs.oracle.com/javase/tutorial/uiswing/
As always, break your requirement/functionality into smallest possible units, and code, test, repeat per unit.

In case you run into trouble, show us your code, tell us where you are stuck and we will help point you in the right direction


[How to ask questions] [Donate a pint, save a life!] [Onff-turn it on!]
Winston Gutkowski
Bartender

Joined: Mar 17, 2011
Posts: 7077
    
  16

Jeff Karr wrote:How would I make the GUI work and function with the underlying code if the GUI classes don't contain it? Do I borrow from another class?

Well, I'm certainly no GUI expert, but I'd definitely get your temperature conversion working first - and keep it completely separate from your GUI.

Winston

Isn't it funny how there's always time and money enough to do it WRONG?
Artlicles by Winston can be found here
Neelesh Srinivasan
Greenhorn

Joined: Jan 23, 2013
Posts: 11
Your absolutely right Winston. Following the MVC Architecture.
Jeff Karr
Greenhorn

Joined: May 02, 2013
Posts: 10
I am sorry about the delay in response. I have a good reason why I took so long, but then again, it's a private matter so don't take it personally, besides, I doubt you even want to hear the story anyway.

so!

Here we go, I still don't know how to implement or use extends and abstract classes to create this gui interface, so I'm going to read the tutorials you guys posted. I imagine that I'm going to create a class which implements a class, and that class is going to be an extension of another class? the first class containing the GUI information, which would be implemented, and a final class which extends this as a super class? Please, guide a NOOBLET.

I imagine, that I'm going to create a separated superclass and that class is going to be used as an extension? my question is, how do I use multiple classes in a project? and secondly, how in the bee hives nest do I compile and run a java file without an IDE to do babies work?

So I worked a little bit on it last night, here's what I got so far, So far I know to program a a frame (lol); have no idea how I'm going to combine it with other classes (which have the calculations to them. anyways, heres the code, this took about 5 minutes to write so it's very sub-par, I'm sorry, you don't have to help me put the pieces together because I already know what to do when it comes to creating this calculator without the interface, it's adding the the GUI that's really confusing me.




I will return in about 5 hours with an updated code and to check up on this thread, as you can see I'm struggling trying to find out how to use implement and extends here, and how many classes to make, and how to make the classes work together all without an IDE because someone else on this forum said that noobs shouldn't use IDE's.

all the best,

-Jeff. (p.s. my website should be back up and running once I save up about 4-8 checks.

Jeff Karr
Greenhorn

Joined: May 02, 2013
Posts: 10
Here are some classes I just wrote on the fly, gonna work on studying layout managers now. to be honest I'm just jumping into the fray, I have little to no idea what I'm doing, but I'm going to study layout managers right after. So please help me out thanks in advanced.






Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 36520
    
  16
I have had to break some of the long lines inside the code tags because they mess up the formatting. You can see how it should be done. You appear to have missed out some quote marks in your postings.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 36520
    
  16
You have got an = sign bfeore F in your pseudo‑code. That will translate into Java as a serious logic error.
Jeff Karr
Greenhorn

Joined: May 02, 2013
Posts: 10
Anyone else got any ideas? Or anyone can point me in the right direction, or at the very least give me/tell me the subject(s) I need to study in order to accomplish this?

-Layout managers
-GUI
-Coding classes, methods, instance variables
-Interfaces
-Threads
-abstract/final keywords
-inheritance/polymorphism.

I'm taking an internship at Robert half technology, wish me luck fellas.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Developing a temperature calculator with GUI
 
Similar Threads
kind of confusing
Scott, Gregg, All of the Ranchers: Need help on my life.
Input/Output Question...
How can I get my temperature converter program to display negative numbers
Digital Signal Processing (DSP, FFT, Spectrum)