title: Set JLabel Visible when JButton is clicked in actionPerformed
body: <p>I am trying to get a JLabel to appear when a JButton is clicked. I have added an action listener and added the component to the layout. I am using the label1.setVisible(true) when the JButton is clicked in actionPerformed. I still can't get it work. Can some look at my code?</p>
  
  <pre><code>public class LearnAppMain extends JFrame implements ActionListener {
  
  // Define variables
  public JButton button1;
  public JLabel label1;
      public JTextField field1;
  
      private Image image1;
  private String apple = "apple.jpg";
  
  public LearnAppMain() {
  
      ImageIcon image1 = new ImageIcon(this.getClass().getResource(apple));
      JLabel label1 = new JLabel(image1);
  
      button1 = new JButton("A");
      button1.addActionListener(this);
  
      field1 = new JTextField(10);
  
      // Create layout
      setLayout(new FlowLayout());
  
      // create Container
      final Container cn = getContentPane();
  
      cn.add(button1);
      cn.add(field1);
      cn.add(label1);
  
      // setLayout(new FlowLayout());
      setSize(250, 250);
      setLocationRelativeTo(null);
      setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      setVisible(true);
  }
  
  @Override
  public void actionPerformed(ActionEvent e) {
  
      Object source = e.getSource();
  
      if (e.getSource() == button1) {
          label1.setVisible(true);
          field1.setText("Apple");
      }
  
  }
  
   }
  </code></pre>
  
  <p>I have my main method in another class file. The error I get leads me to the label1.setVisible(true);</p>
  
  <p>Every question I've seen they say to do this, but I'm wondering if there is something else that needs to be added.</p>