Last week, we had the author of TDD for a Shopping Website LiveProject. Friday at 11am Ranch time, Steven Solomon will be hosting a live TDD session just for us. See for the agenda and registration link
This is how I did it: -Built my GUI in one class file -Built my engine (run all calcs pertinent to GUI selections) in its own class file -Main Method in its own class file(just how I did it. Not needed obviously)
My engine class extends the GUI class.
In a method inside of my engine class the code that reads the combo box looks like this:
First thing, I only included the relevant code that you are asking about, except the bit with "Age". That was just to show you some transition.
textaReadOut.setText --> textaReadout = text area readout (just explaining my verbage ). This is the JTextArea for displaying your info. Apply the .setText to tell your program to print in that specific JTextArea (.setText is like System.out.println... but for GUIs).
comboSex.getSelectedItem() prints whatever was selected in the JComboBox that I called comboSex (fyi, comboSex is a selection between "male" and "female").
cannot find symbol symbol : constructor Editor() location: class Editor
The likely short answer is put in a super(); call.
The likely longer answer is:-
Go and compare the constructor in your superclass (Editor) with what you are calling. How many constructors do you have in Engine? Are you calling them from one another using the syntax? Remember every constructor in your subclass has to have a route (direct or indirect) to call the constructor for the superclass, unless you have a public [or protected] no-argument constructor in your superclass.
SO:- If you have a public no-argument constructor in your superclass, you oughtn't to get that error message. If you haven't written a constructor for your superclass, your compiler will impute a public no-argument constructor, and you oughtn't to get that error message.
BUT:- If you only have public [or protected] constructors with arguments in your superclass, then every constructor in your subclass must call one of those constructors with a statement. If you have overloaded your subclass constructors, you either have to call the superclass constructor directly with super(something); in each constructor, or use this(); to call another constructor which then uses super();
I hope you get your program to work and I hope you can understnad what I have written. CR
I took some old code that I wrote and trimmed it down to show you how I did something similar to what you are asking about. In my example I used your class names Editor and Engine. The main method is nested in class Editor. So scope on my code and tell me what you think:
Here is your Editor:
Here is your Engine code:
If anybody sees useless code that pertains directly to how to accomplish John's question please feel free to help me trim that fat. No need to point out stuff like "int x = 0". It's obvious that that isn't used. Please point out things that are needed, but can be reduced (ie general code format, etc).
John, let me know if this properly addresses your original question.
Thanks again for the replies (and patience) guys; you�ve been helping me get my head round some stuff that normally have me hitting my head against a wall. This is a great forum.
Ryan, I get a strong feeling that that would solve my problem but for one other problem. The Jcombobox I�m using is basically being populated from a file reader in my editor class, through a fairly contrived method of reading its values in line by line, taking a substring of those lines and converting them to a hashset to remove duplicate values. The end result is the combobox in my editor class is populated with an array of strings called �comboarray�.
(it took perseverance, heh)
The thing is though that this is all happening in another action performed method.
So what I end up with is a comboarray, equivalent to the �sex� and �activity� strings your example that you populated your equivalent JComboBoxes with. The problem is, I think, that because my comboarray is being built in another ActionListener / action performed in my Editor class it can�t be accessed outside the action event, as they aren�t capable of returning values. I think.
So that means in the Engine class you showed me,
I don't think it would work for me if 'sex' or 'activity' were replaced with my 'comboarray'.
Does that sound right? It's the only way I can explain this still not working, unless I messed up my call to my superclass constructor. Thanks again
Hey, John. I won't be able to think on this for a few days. As soon as I have a chance, I'll consider what you wrote, and see if I can come up with a solution. Hopefully somebody will figure it out before then.
***edit: It's been a little over a month... I did not figure it out since then, but honestly I've been preoccupied with other issue. Have you had any luck? [ March 14, 2007: Message edited by: Ryan Giomi ]
This is my favorite tiny ad:
free, earth-friendly heat - a kickstarter for putting coin in your pocket while saving the earth