This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
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?
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.
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.
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
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.
Isn't it funny how there's always time and money enough to do it WRONG?
Articles by Winston can be found here
Joined: Jan 23, 2013
Your absolutely right Winston. Following the MVC Architecture.
Joined: May 02, 2013
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.
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.
Joined: May 02, 2013
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.