• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Adding a GUI to an existing program

 
Debra Simeroth
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello!

I have a simple inventory program that I will be adding a GUI to for an online programming class. I don't want to start off on the wrong foot, so before I do that, I will ask. Should I implement a new class for my GUI and invoke my other methods from there, or should I modify my existing class to incorporate the GUI elements? My best guess is that I should implement a new class, but being a newbie, don't want to unnecessarily complicate my life. Thanks in advance for the help.

Deb
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34863
369
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Debra Simeroth wrote:My best guess is that I should implement a new class, but being a newbie, don't want to unnecessarily complicate my life.

Your instinct is a good one. Implementing a new class is less complicated than having a giant monstrosity of a file!
 
Campbell Ritchie
Sheriff
Pie
Posts: 49849
70
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Anybody who worries about their classes getting complicated is on the right path . . . but we usually discuss GUIs on a different forum, so I shall move you there.
 
Debra Simeroth
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I was hoping this would be easier, but it doesn't appear to be. I have been at this since 10 am... stopped to get food and bring it back to my isolated room, and went at it again. I have read a myriad of materials, tutorials and even tried my hand at some code, but keep ending up with the same problems. How do I connect the code I have with this GUI? Specifically the code in my main method from //print welcome statement to //end method main which needs to print in a GUI. No bells and whistles yet, just a display. I figured that my code in my main method needed to be more modularized, so I tried that for a few hours.. getting nowhere. I also tried just referencing some other methods and also got nowhere. It is now 8:30 at night and I am humbly asking for help (again). I would insert the banghead at this point, but I am too tired to do this.. I will just cry Below is what I have accomplished... please don't laugh I am totally new at this.






There is one more class of code, however I don't think it is relevant to this discussion so I won't bore you... Thanks in advance.... and thanks from my husband and children who are missing me and want me to come out of this room.... Only two more weeks of this class, then I will study this at a more reasonable pace! I like it, but really need more time to absorb the wealth of information necessary to code properly!
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
this is just a single .java file, having changed a couple of things to be able to compile/run it.

copy/paste/compile/run it as-is and you should get roughly the same output as your existing program (total value $30.172.75)

I've added a very simple gui, just to start you off, so after running it as-is, comment out your InventoryTest class, and uncomment my Testing class
recompile/run then click the calculate button.

if you want to add components to the gui, only use swing components, not the awt ones you were mixing in with the code you posted.

 
Debra Simeroth
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am on my knees thanking the Dear Lord for this forum! I will study what you have shown me here.... I may have questions later... In fact I am sure I will! Mr. Dunn, you are most excellent!
 
K. Tsang
Bartender
Posts: 3509
16
Android Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Debra. Your current approach can be simplify so much in my opinion. Given you have your old non-GUI version working as it. Now the main program/class is the non-GUI version. You building the GUI class. So all you need to do is 1) duplicate the non-GUI main class as its separate class then 2) modify your main program to call either non-gui or gui.



And if you really want modularity and OO - look into class design (eg sharing methods and stuff), separate the common stuff to its own class and modify the non-gui and gui class accordingly.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic