title: Why I should define a JLabel before a addActionListener?
body: <p>I have one JLabel and one JButton into JFrame. I write code for actionPerformed  event of JButton like following:</p>
  
  <pre><code>btnOK.addActionListener(new ActionListener() {
          public void actionPerformed(ActionEvent arg0) {
              lblA.setText("Hello"); // error here
          }
      });
  final JLabel lblA = new JLabel("");
  </code></pre>
  
  <p>but i get following error:</p>
  
  <pre><code>lblA cannot be resolved
  </code></pre>
  
  <p>however if I placed define of JLabel before addActionListener like following my problem solved:</p>
  
  <pre><code>final JLabel lblA = new JLabel("");
  btnOK.addActionListener(new ActionListener() {
          public void actionPerformed(ActionEvent arg0) {
              lblA.setText("Hello"); // error here
          }
      });
  </code></pre>
  
  <p>Also if i define a variable after it, i get similar error and i should define variable before it.</p>
  
  <p>But in C# i can define a variable after one method and use variable into method.</p>