title: How can I access a variable from an actionListener insider another actionListener?
body: <pre><code>private int var = 0;
  
  test(){
      ActionListener actionListener = new ActionListener() {
          public void actionPerformed(ActionEvent e) {
              String selection = (String) items.getSelectedItem();
  
              for (int i = 0; i &lt; itms.length; i++) {
                  if (selection == itms[i]) {
                      var = 10 + i;
  
                      System.out.println(var); // prints the desired value
                  }
              }
          }
      };
  
      System.out.println(var); // prints 0 but why not desired value???
  }
  </code></pre>
  
  <p>This actionListener is for a combo box. I want to take the value of the selected item in the combo box and give that to another actionListener which will append a new value to the var from the original actionListener based on which JButton is selected. How can I get the value of var from inside this actionListener and use it in another actionListener that is also in the same constructor? Is that even possible? Is there a better approach?</p>