So I am making a panel project that calls three panels. Panel one holds all information and the other two panels are panels that open up when I press a button. How it works is I call the first panel, press a button, second panel opens. Then in the second panel I plug in a password. If it is correct, a third panel will open. I need to call values from the first panel into the third panel and those values act as sort of like counters. In the third panel it will display all the counters that were added as well as the complete sub total, tax, and total that the program accumulated during its run time duration. I know how to use constructors, accessors and mutators, but the values I need are generated in an event when I press a button. I am trying to figure out how to call those values from the event into the third panel. Here is my code, sorry in advanced if it seems sloppy. I've been trying different things so it might seem a little disorganized.
Here is the main panel holding the information. The counters counterp21 through p24, subTotalp2, taxP2, and realTotalp2 are the values that need to be carried over to the third panel and displayed in the textfields. I will post half of the panel, at least the important parts. Notice that I made my constructor initialize double variables which are the subTotalp2, taxP2, and realTotalp2. In this instance, I am not calling the counters just yet due for the sake of testing purposes. TempListener2 is the event that holds the variables that I am trying to call into the third panel.
And here is how I am trying to call those values into the third panel. If you notice, the class is actually called AppleRegisterPanel2; this is because I made this before the second panel that is now implemented. This panel now acts as the third panel.
So my question is; is what I am trying to do even possible? I know the information that is being stored is inside a void that is acting as an event. As it stands the code that is called in the third panel is 0.0. I know this code seems sloppy but I've been trying different things with no result. Any ideas of how I can do this if at all?
I haven't read all your code, but I am worried by what you say about panels holding information. A panel should never hold any information. It is there to display it. You should have classes and objects which do all the calculations when you pass the data via the command line. Then you can use other code to get the data to and from a GUI.
There are several ways you can distinguish floating‑point numbers from integers in text; you can try regular expressions or a Scanner. Look at what I posited about Scanners a few minutes ago. Try here. Instead of while(myScanner.hasNextInt()) try ….hasNext() and try if-elses with hasNextInt and hasNextDouble.
There is something odd about new GUIs opening when you push a button. You may mean appear and disappear, which is something different. Look through the Java Tutorials for how to lay out components; I think card layout may produce the exact effect you want.
posted 4 years ago
Thanks for responding! I appreciate your help!
The reason why the event is holding the values is because when I press the buttons values are added to the variable. Which is weird because the variables I am using are attributes. So the event handler shouldn't really hold the values back from me accessing. The entire program creates a register like program that has multiple panels open when certain buttons are pressed.
Button 1-4 add values to sub - total, tax, and total. As well as a counter to the quantity of that item that was pressed. When I complete that transaction, the values are reset. The issue is I need valued that store that exact same data, but doesn't get reset so it can track the number of items sold, and the sub-total, tax, and total of that entire given transaction. So if I reset the first variables 3 times, those secondary variables are never reset and are tracked. It is those secondary values that are storing the information that I need to transfer over to the third panel.
I've tried accessors, mutators, and creating an object implementing the first panel constructor into the third panel. But no success. I'll take a look at the tutorials when I get off work and do a test run of the Card layout. Hopefully I can find a way as this assignment is due in two days, but if not oh wells. Lol.
posted 4 years ago
You are going about it the wrong way. Delete the entire GUI code and get something which will add tax total etc from the command line. You will want bill objects and charge objects. When you have got that working, then you can put a GUI back
I've got no option but to sell you all for scientific experiments. Or a tiny ad:
Download Free Java APIs to Work with Office Files and PDF