Hank Harrison wrote:Ok so I have this gui built but i'm in the last steps and i can't figure out how to do this last calculation. I want the user to input and odometer (in feet) and have it use that and the Duration (in hours) to calculate speed in feet per second. Ive been trying to reference it using various methods but I'm stuck.
OK, well first off, I'm no GUI expert, so plugging it into your GUI is up to you, but what I DO know is that this calculation almost certainly has
nothing whatsoever to do with your GUI, so my advice would be to set up a
separate class to do it. And that class should NOT have a single line in it that defines or references a 'J' class (JFrame, JPanel etc.).
I have it set as a string but whenever i try to pretty much use somewhat the same formula i did for total time it just gives me errors.
Well, that might be your problem right there. Strings are NOT numbers. Have a look at the
StringsAreBad page for more details.
How do I use that number the user inputs into a formula with the output of the Duration? Which method should i use? thanks :-)
Well, that'll depend on what kind of number you need; but just one might be
Double.valueOf(String).
But whatever you do, you
must convert that String to a number - and that conversion
must allow for the fact that your user is a complete idiot and might enter "jsdhfg.0" instead of a proper number.
But the main point is: A distance calculation is a distance calculation, and it can be used
anywhere. So don't define it directly in your GUI.
Winston
[Edit] Too slow.