I have made a queue linkedlist, my main jFrame window is called "UI" on which there is a button "Donate" after pressing it a new jFrame window called "Donate" opens setting Visibility of previous jFrame(UI) to false (setVisible(false)).
jFrame "Donate" contains some text field and a "Donate Blood" button in the end, after filling out the text fields we need to press the "Donate Blood" button so that the entered values in text field should be stored in linkedlist and then setting jFrame "Donate" Visibility to false and jFrame "UI" to true to return back to our main jFrame window.
The problem is that every time I click "Confirm Donate" my data is not linking, for e.g: 3 people donated
When I traverse it I can only see the last entered name, where did John and Matt disappear to?
Donate button in "UI" action listener code:
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
Donate d = new Donate();
this.setVisible(false);
d.setTitle("Donate - Blood Bank");
d.setVisible(true);
}
Donate Blood button action listener code which calls to donate jFrame window:
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
UserInterface ui = new UserInterface();
BloodBank bb = new BloodBank();
enQueue(jTextField1.getText(), (int)jSpinner1.getValue(), (String)jComboBox1.getSelectedItem(), (String)jComboBox2.getSelectedItem());
first.Display();
this.setVisible(false);
ui.setTitle("Blood Bank");
ui.setVisible(true);
}
After debugging it many times I found out that if I remove this line of code from the button action listener and stop the jFrame "Donate" window from going invisible my queue linked list works fine, is setVisible(false) discarding my previous save data? And how can i fix this?
this.setVisible(false);
To help better understand here are some screenshots:-
Donate button in "UI" jFrame:

"Donate" jFrame window:

Each time you are creating a new instance of Donate in the first actionlistener and that of UserInterface in the second actionlistener. If your list is related to the instances of these frames, then you are loosing them. Also, it is not and advisable thing to do. You could create the instances of both the frames in some way so that it can be accessed from both the actionlisteners and then just call setVisible() on the same instances. This should solve your problem.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With