I'm trying to make my first program with java. It's a budget program, to manage your expenses. To do so, i created a frame with 9 panels. 1 north, one south, and a center panel, the center panel is the one where i have an issue, the centerpanel is devided by 6 panels. (like in the picture) : https://ibb.co/mYUhQb
I have created a total value in Cat1Paneel, Cat2Paneel, Cat3Paneel and in Cat4Paneel This works just fine, and the JTextField "subTotText" shows the value i need.
But in som5Paneel i want to add all 4 totals "subTotText" of the 4 different panels, in the JTextfield huidigeMaandText. But i'm stuck on how to make this possible.
Can any of you help me?
The code for the Cat1Paneel, Cat2Paneel, Cat3Paneel and in Cat4Paneel is : (they are all almost the same so i'll show just 1)
The Kassa i am using to get the value is :
And the panel where i want to have the total of the 4 panels has this code:
Sorry for the long post, help would be very much appreciated!
Why are you subclassing JPanel? You don't appear to need to subclass it; you can use plain simple JPanels and add the other Components to them. If you do subclass things, Category1XXX isn't a good name for a class because it requites knowledge of what category 1 means. Also, all class names should start with CapitalLetters.
Why have you got two main methods? Why are you calling a subclass of JFrame xxxPaneel in line 9?
I can see some strange design in your handler classes. For one thing, are they all doing something different from one another? I think you would do better to have a single class, and pass the text components etc. as parameters to a constructor. Also you are doing the arithmetic in the actionPerformed method before passing the total to the Kassa object. That doesn't look right, either. I think you should pass the different amounts to Kassa and let it do all the arithmetic. Also maybe you should design a Payment class to encapsulate the amount and date. Let the Kassa object return a total for month or whatever, and your Listeners can update that display. You would have to consider how to calculate a total for the month. If you have a List<Payment>, you can iterate it looking for the months, but that will run in linear time and will affect performance. You can partition your List into a Map<Month, List<Payment>>, but that requires a bit of familiarity with the use of Maps. Such a Map looks a better design, however. Also beware of the methods of the Kassa object. You appear to have a fixed number of methods, and that ties the Kassa to having that many values, and you are losing flexibility in that class.
Don't use doubles for money. There is an example of what you should use here, and in the link in the post following.