• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Need help with adding to totals

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
reply
    Bookmark Topic Watch Topic
  • New Topic