title: How to go back to a JFrames in Java
body: <p>I have a button in a JFrame, if pressed, it takes us to another frame. 
  I used this code:</p>
  
  <pre><code>private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {
  
      SecondForm secondform = new SecondForm();
      secondform.setVisible(true);
      setVisible(false);
      dispose();
      }
  </code></pre>
  
  <p>So the new frame opens and everything is ok. Then i placed another button -in the second frame- in order to go back to the previous frame. I used this code:</p>
  
  <pre><code>private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                         
  
      MainForm Mform = new MainForm();
      Mform.setVisible(true);
      setVisible(false);
      dispose();
  }                                        
  </code></pre>
  
  <p>The thing is, i don't think this is the right way to do this. What i want is to:</p>
  
  <ul>
  <li>hide the first frame</li>
  <li>show the new second one</li>
  <li>dispose the second one</li>
  <li>show again the first</li>
  </ul>
  
  <p>Is there a way to do that using the first MainForm instance and not creating a new one every time i want to go back. 
  I monitored my program and every time i go back and forth the frames and as i suspected, the ram being used by it keeps increasing.</p>
  
  <p>Thanks in advance.</p>
  
  <p><strong>EDIT :</strong> I have a login system and when the user put the correct credentials a new ManiForm instance is created.</p>
  
  <pre><code>MainForm Mform = new MainForm();
  Mform.setVisible(true);
  </code></pre>
  
  <p>That is the instance i want to use. Ii there a way to make MForm visible again from the secondform?</p>
  
  <p>First of all thanks for the help!</p>
  
  <p>I agree that it is easier not to use more than one JFrames, but can you please tell me which is the better way to do what i asked in the first post?
  The answer <strong>Robin</strong> gave me is very nice but i don't know what to put as an argument there*:</p>
  
  <pre><code>java.awt.EventQueue.invokeLater(new Runnable() {
  
          public void run() {
      *   new SecondForm().setVisible(true);
          }
      });
  </code></pre>
  
  <p>It's from the auto-generated code from NetBeans.</p>
  
  <p>I tried </p>
  
  <pre><code>new SecondForm(super).setVisible(true);
  </code></pre>
  
  <p>but i still get compile errors. Apparently i must put <code>super.something()</code> but i don't know what. I tried many but no luck.</p>