title: Update jPanel background color when a button is pressed
body: <p>I'm just starting with Java and I wanted to make a little program that opens a jFrame with a text field in which you can write a number. Then you press a button and another jFrame with a jPanel, which will turn green if the number is even, and black if it's odd. I edited the code of the jPanel so that the color changes depending on the number, but the problem is that it will only work once. If I write "2" and press the button, the jFrame will appear with a green panel, but then if I write another odd number and press it again, the frame will stay green. </p>
  
  <p>How could I solve this so that the background color changes whenever I press the button? I should also say that I made an "if-else", so that you could only open the second jFrame once because I didn't know how to make it close and then open again, so maybe that has to do with the problem. Thanks!</p>
  
  <p>This is the code in the Panel. To make it easier, I tried to just turn it green if a zero was introduced, and now it doesn't even work:</p>
  
  <pre><code>jPanel1 = new javax.swing.JPanel();
  if ("0".equals(Taller2.opcion)) {
  jPanel1.setBackground(new java.awt.Color(0, 255, 0));
  }
  else {
  jPanel1.setBackground(new java.awt.Color(0, 0, 0));
  }
  jPanel1.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(255, 255, 255)));
  
  // Code of sub-components - not shown here
  
  // Layout setup code - not shown here
  
  // Code adding the component to the parent container - not shown here
  </code></pre>
  
  <p>Here is the pretty basic main class:</p>
  
  <pre><code>public class Taller2 {
  
  /**
   * @param args the command line arguments
   */
  public static String opcion;
  public static boolean panelabierto;
  public static void main(String[] args) {
      Pregunta a = new Pregunta();
      a.setVisible(true);
      opcion = null;
      panelabierto = false;
      }
  }
  </code></pre>
  
  <p>The second jFrame (the one with the jPanel inside) only has the basic code generated by Netbeans on the designer. If you need the code for the jFrame with the text field, I could add it too, although I believe the problem lies within the jPanel.</p>