aspose file tools*
The moose likes Beginning Java and the fly likes wrapping program in gui Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Beginning Java
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: 60077
    
  65

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.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 36579
    
  16
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: 7081
    
  16

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?
Artlicles by Winston can be found here
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
Having trouble writing a method that factors negative numbers.
array out of bounds
Initializing variables
bit values of an integer
GCD/LCM problems