title: How to access a variable defined in a Listener from the main class?
body: <p>I have a problem with a variable in <code>MyFrame</code> class. I want to have in <code>MyFrame</code> class the value of a variable that is defined in a combobox listener.</p>
  
  <p>This is my situation: I have a combobox with some friends' name. I have put a listener to the combobox which has to return the surname of the selected friend.
  I want to insert the value of <code>surname</code> in a command in <code>MyFrame</code> class, but there are some problems: once setted <code>surname</code> as <code>final</code> (because it has to be used in the Listener), I have an error that say: </p>
  
  <p><code>The final local variable surname cannot be assigned, since it is defined in an enclosing type</code>.</p>
  
  <p>What is (or are) the matter(s)? Here I post my code:</p>
  
  <pre><code>public class MyFrame extends {
  public static void main (String[] args)
      {
          //other 
          String [] names = {"john","al","jack"};
          final String surname=null;
          JLabel nameLbl = new JLabel("surname: " + surname);         
          JComboBox box = new JComboBox(names);    
          JPanel centralPnl = new JPanel();
          centralPnl.add(nameLbl);
          centralPnl.add(box);            
          box.addItemListener(new ItemListener()
          {
              @Override
              public void itemStateChanged(ItemEvent e) {                 
                  if (e.getStateChange() == ItemEvent.SELECTED)
                  { 
              // Here operations from database 
              //that return friends' surname under the variable name of "result"
                      surname = result;                       
                  }
              }
          });
      }
  }
  </code></pre>