I've made the Swing 'face' for a program that does electrical calculations. It's looking great, but I now seem faced with a bewildering set of options as to how to implement the underlying calculation. The code is getting alittle long, so I will try to describe in general terms.
The panel I'm working on calculates voltage drop:
1. The user can select from a group of two radio buttons which chooses the type of formula for the calculation.
2. The user chooses values for (7) different variables, (3) of which are only present in one of the types of the formula. User chooses with editable and non-editable combo boxes.
3. There are an additional (4) variables, and the user chooses which one these will be solved for with more radio buttons. There are also some additional radio buttons next to these which change the format (ie feet, meters) of the variables.
4. The result is displayed in a text field, and updated whenever the user changes a value.
I don't think this requires much processing power so this is all being done in the event dispatch thread - good because I don't know much about threads yet.
There are a few different ways with my limited knowledge of Java and programming that I can think of the implement this, and probably a few I don't know about yet. Even the ones I know about still seem a little 'hazy' to me.
A. Use event listeners that fire when basically any legal change is made to the panel, and pass all of the variables as pretty much string literals to a monolithic logic class constructor that parses everything and figures out the result and has a method to return the result. I guess it could have different constructor signatures that could help in figuring out what to do. Every time the user changes the panel a new object is created that figures out the result. This seems like it might be ugly and hard to work with.
B. "Parent Factory" - Do pretty much the same as (A.) except pass the variables as arguments to a method in an abstract class that figures out what to do and creates an instance of one of its subclasses. This will at least make working on the application logic a little easier, I think.
C. Observer and Observable? I don't really know much about how this works yet.
D. Bindings? Same thing - I don't really know much about this yet.
I will also need to string calculations of this type together in a different module. So I want to be reuse the logic.
So - which rabbit hole should I be jumping down? I don't want to code myself into a corner.
If you are posting in other forums, please do tell us about that. That is because, people reading the thread can check the other posts first to see if it has already been answered and if so, don't have to spend their time.
Please read this page to know more about the same: BeForthrightWhenCrossPostingToOtherSites
SCJP 1.4, OCMJEA/SCEA 5.0.
subject: First timer Swing application, need help implementing the application logic