• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

wrapping program in gui

 
Kirstie Fran
Ranch Hand
Posts: 33
Android Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,
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:
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64620
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What kind of GUI? Swing? Web?

Regardless, it's not going to be that simple. Depending upon which type of GUI you choose, the method of accepting input will change drastically from reading in from the console.
 
Campbell Ritchie
Sheriff
Posts: 48382
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Winston Gutkowski
Bartender
Pie
Posts: 10099
56
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

Winston
 
Kirstie Fran
Ranch Hand
Posts: 33
Android Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear Bibeault wrote:What kind of GUI? Swing? Web?

Regardless, it's not going to be that simple. Depending upon which type of GUI you choose, the method of accepting input will change drastically from reading in from the console.

it would be a swing gui. I'm using a jframe.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic