title: Using object created in Jbutton ActionPerformed method in Jlist
body: <p>I am trying to design a user interface that allows the user to load a file containing information about persons into the system and then access information about single persons. 
  I have a Method getpersons that gets information from an ArrayList and creates an object PersonList. The ArrayList is generated by reading information about people from a .txt file. PersonList again contains single Person objects. 
  Now I created a JButton and in the EventListener method I call the first method.
  So basically upon clicking the button my program reads the file and creates an object PersonList.
  Then I would like to loop through the PersonList object and add person objects to the jlist. Upon clicking the object in the J list I would like to display the information contained in the person object in a JTextArea. Now my first thought was to pass the person objects directly to the Jlist. But I don't know how to get my JList to accept my specific person objects. </p>
  
  <p>The person class looks somewhat like this:</p>
  
  <pre><code>public class Person 
  {
  
      private String personname;
      private String personage; 
      private String personaddress; 
      .....
  }
  </code></pre>
  
  <p>And my JButton code like this</p>
  
  <pre><code>private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                         
      ArrayList&lt;String&gt; personlist = readFile("data/persons.txt");
      PersonList persons = getpersons(personlist);
  
  
      for(int i = 0; i &lt; persons.getsize(); i++)
      {
  
      JList.addItem(persons.getperson(i));
      }        
  } 
  </code></pre>
  
  <p>Another idea would be to simply display the name of the person which is a string  in the Jlist. Then I would compare the name the user clicks in the Jlist to my persons in the PersonList object and display the information of the corresponding person in the text area. But this would require me to get the PersonList object out of the jButton1ActionPerformed method which is private (and cannot be changed to public) and pass it to the JListActionPerformed method.
  Any help would be appreciated
  I am not sure whether this is a good approach. If you have suggestions for a better approach to doing this, I would also be glad.</p>