title: Adding JPanel onto another JPanel after button click
body: <p>I'm using Netbeans IDE to make a gui application. I have a JFrame with a JPanel inside it. After a button click I want to display a different JPanel inside the first. The other JPanel is in a different file. How would I go about doing this? If this is not practical I don't mind replacing the first JPanel with the second one. </p>
  
  <p>I've tried the following but it doesn't seem to work. I'm new to Java and Gui programming so I would appreciate any help I can get.</p>
  
  <pre><code>private void jButtonActionPerformed(java.awt.event.ActionEvent evt) {        
      JPanel2 jPanel2 = new JPanel2();
      JPanel1.add(jPanel2);
  }
  </code></pre>