title: NullPointException error when setting attributes
body: <p>I'm getting a NullPointerException error at line 77 <strong><code>lblNewLabel.setVisible(false);</code></strong> 
  which is called from line 65 <strong><code>runTest();</code></strong> in the following code.  (This is a dummy project I wrote to simulate a problem I'm having in a larger project).  What I'm trying to do is change the attribute of several fields, buttons, etc based on user action at various places in the project.  I would like to group all the changes in a separate method that can be called from various other methods.  I'm still a Java novice, having come from some Visual Basic and Pascal experience.  Seems like what I'm trying to do should be straight forward, but for now, I'm at a loss.  Thanks in advance for your suggestions.</p>
  
  <pre><code>package woodruff;
  
  import java.awt.EventQueue;
  import javax.swing.JFrame;
  import javax.swing.JPanel;
  import javax.swing.border.EmptyBorder;
  import javax.swing.JLabel;
  import javax.swing.JButton;
  import javax.swing.SwingConstants;
  import java.awt.event.ActionListener;
  import java.awt.event.ActionEvent;
  import javax.swing.JTextField;
  import java.awt.event.FocusAdapter;
  import java.awt.event.FocusEvent;
  
  public class MyTest extends JFrame {
  
      private JPanel contentPane;
      private JTextField txtHasFocus;
      private JLabel lblNewLabel;
  
      /**
       * Create the frame.
       */
      public MyTest() {
          initialize();
      }
  
      private void initialize() {
          setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
          setBounds(100, 100, 237, 161);
          contentPane = new JPanel();
          contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
          setContentPane(contentPane);
          contentPane.setLayout(null);
          final JLabel lblNewLabel = new JLabel("This is a label.");
          lblNewLabel.setHorizontalAlignment(SwingConstants.CENTER);
          lblNewLabel.setHorizontalTextPosition(SwingConstants.CENTER);
          lblNewLabel.setBounds(10, 25, 202, 14);
          contentPane.add(lblNewLabel);
  
          JButton btnShow = new JButton("Show");
          btnShow.addActionListener(new ActionListener() {
              public void actionPerformed(ActionEvent arg0) {
                  lblNewLabel.setVisible(true);
              }
          });
          btnShow.setBounds(10, 50, 89, 23);
          contentPane.add(btnShow);
  
          JButton btnHide = new JButton("Hide");
          btnHide.addActionListener(new ActionListener() {
              public void actionPerformed(ActionEvent e) {
                  lblNewLabel.setVisible(false);
              }
          });
          btnHide.setBounds(123, 50, 89, 23);
          contentPane.add(btnHide);
  
          txtHasFocus = new JTextField();
          txtHasFocus.addFocusListener(new FocusAdapter() {
              @Override
              public void focusGained(FocusEvent arg0) {
                  // Following results in NullPointerException error
                  // at woodruff.MyTest.runTest(MyTest.java:77)
                  runTest();
              }
          });
          txtHasFocus.setHorizontalAlignment(SwingConstants.CENTER);
          txtHasFocus.setText("Has Focus?");
          txtHasFocus.setBounds(67, 92, 86, 20);
          contentPane.add(txtHasFocus);
          txtHasFocus.setColumns(10);
      }
  
      private void runTest() {
          lblNewLabel.setVisible(false);
      }
  
      /**
       * Launch the application.
       */
      public static void main(String[] args) {
          EventQueue.invokeLater(new Runnable() {
              public void run() {
                  try {
                      MyTest frame = new MyTest();
                      frame.setVisible(true);
                  } catch (Exception e) {
                      e.printStackTrace();
                  }
              }
          });
      }
  }
  </code></pre>