title: How to change JPanel's color from another class. Java
body: <p>I've got a problem with changing JPanels color from another class. 
  I'm trying to change it by clicking a button. I am creating an application where user can pick a colour theme what he wants.</p>
  
  <p>First class:</p>
  
  <pre><code>public class First extends JFrame {
  
      public JPanel contentPane = new JPanel();
      public JPanel panel = new JPanel();
  
      public First() {
  
          JButton btnNewButton = new JButton("New button");
          btnNewButton.addActionListener(new ActionListener() {
              public void actionPerformed(ActionEvent arg0) {
                  Second s = new Second();
                  s.startSecond();
              }
          });
      }
   }
  </code></pre>
  
  <p>Second class:</p>
  
  <pre><code>public class Second extends JFrame {
      First f;
      private JPanel contentPane;
  
      public static void startSecond() {
          EventQueue.invokeLater(new Runnable() {
              public void run() {
                  try {
                      Second sframe = new faijaso();
                      sframe.setVisible(true);
                  } catch (Exception e) {
                      e.printStackTrace();
                  }
              }
          });
      }
  
      public Second() {   
          JButton btnNewButton = new JButton("New button");
          btnNewButton.addActionListener(new ActionListener() {
              public void actionPerformed(ActionEvent e) {
                  f.panel.setBackground(Color.red);
                  f.panel.repaint();
                  f.panel.revalidate();
              }
          });
      }
  
  }
  </code></pre>