I have simple digital root calculator program that i would like to add a GUI to; rather than create a whole new program, someone suggested that i simply wrap the old one in a GUI. any suggestions on how to do this?
Here is the original program:
If you have a calculator with a proper public interface, it is not that difficult really. It might take a long time to learn all the Swing components, however.
Do you have methods like add() subtract() divide() multiply()?
Do you have methods like takeParameter(), takeOperator()?
When you have such methods and you can do this sort of thing, you have a chance of wrapping it in a GUI:-ORYou don’t need to do both; either will work (but differently).
In your case, it would appear that you might only have one operator (Operators.SQUARE_ROOT) or one method (squareRoot()).
Actually what you are doing is working out the transverse sum of the digits modulo 9. I mistook it for square root.
Kirstie Fran wrote:any suggestions on how to do this?
Yes, but it's going to be difficult to achieve with your program as it is: You need to keep your calculator and your input/display (be it GUI, console or browser-based) completely separate.
And that means, as Campbell said, coming up with a public API for your calculator.
Right now, they're all mixed up together, so your first cut should be to remove all those Scanner.get... and System.out.println() statements from your calculator and put them in another class (CalculatorDialog?). Once you have that, you'll probably find it a lot simpler to re-write to use GUI components.
Isn't it funny how there's always time and money enough to do it WRONG?
Artlicles by Winston can be found here