This week's book giveaway is in the Agile and other Processes forum.
We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes wrapping program in gui Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Beginning Java
Reply Bookmark "wrapping program in gui" Watch "wrapping program in gui" New topic
Author

wrapping program in gui

Kirstie Fran
Ranch Hand

Joined: Feb 16, 2011
Posts: 33

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

Joined: Jan 10, 2002
Posts: 56185
    
  13

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.


[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 32654
    
    4
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

Joined: Mar 17, 2011
Posts: 4747
    
    7

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

Isn't it funny how there's always time and money enough to do it WRONG?
Kirstie Fran
Ranch Hand

Joined: Feb 16, 2011
Posts: 33

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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: wrapping program in gui
 
Similar Threads
Initializing variables
Having trouble writing a method that factors negative numbers.
bit values of an integer
array out of bounds
GCD/LCM problems