• Post Reply Bookmark Topic Watch Topic
  • New Topic

Need help with adding to totals  RSS feed

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok so my problem is that when I run this code everything works except when I click the buy button it only displays price for current item selected.
I am having a problem figuring out what I need to do to have the total for every object to continue to add to total when I press the buy button.

 
Marshal
Posts: 56610
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch

I think part of the problem is that you have tried to write a GUI rather than an application. you should write the application and then add the GUI as its display. Now you have over 200 lines of code most of which don't have anything to do with the problem.
Do you mean you want to add the current purchase to a previous purchase to make a total? In which case the only total I can see appears to be a local variable in one of the action performed methods. That will never add anything.

Program4 is a really bad name for a class. The variables should not start with CapitalLetters. Use camelCaseNames. Most of those Components are fields in the frame class; change them all to be local variables in the constructor/setUpGUI method. Don' use null layout. Never use the == operator on reference types. Least of all Strings, because it will sometimes return true.
There must be a better way to set up your combo box than that. Yes, create an Animal class with type and price fields.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!