I am creating a Java application where I am going to have a button. When that button is pressed I want a form with fields like username
, password
and various others to be entered there. In that form there is the Save
button which when pressed saves everything to a file and switches back to the first JFrame.
This is how I do it currently. This is the button code for the first JFrame:
public class FirstJFrame extends JFrame {
private void newJFrameActionPerformed(java.awt.event.ActionEvent evt) {
SecondJFrame pan = new SecondJFrame();
this.setVisible(false);
pan.setVisible(true);
}
}
and this is the code for the Save
button on the second JFrame:
public class SecondJFrame extends javax.swing.JFrame {
private void goBackActionPerformed(java.awt.event.ActionEvent evt) {
SecondJFrame pan = new SecondJFrame();
this.setVisible(false);
pan.setVisible(true);
}
}
This works well enough for me but I have a feeling that I am not doing this right at all and I might create a memory leak since I am creating a new object each time. Is what I am doing correct or is there a better way?