Make each item in the list a an object that contains all the information for a contact, i.e. when you read in a string of info, parse it into different values, each of which is a member of the contact object. You can create each object by passing the data values to the object's constructor. You might also want to consider overriding the toString() method in the object to define what you see in the list. When you click a list item, you now have access to the object that represents the entire entity.
Rob Camick wrote:Why do you have a List of Contacts? The DefaultListModel holds all your Contacts.
If you want a specific contact when the user clicks on the list you get the contact from the ListModel or from the JList itself.
That is the selected item will be the Contact that was selected.
Rob Camick wrote:Well you can use the JList.getSelectedValue() method which will get the data from the DefaultListModel for you.
Rob Camick wrote:Look at your code:
You assign null to the line variable.
john lampard wrote:If I don't assign it to anything, I'll get an error saying "line" may not have been initialized.
because my readStates method handles that problem fine.
Rob Camick wrote:
Well, the readStates() method actually reads some text into the variable.
In your other code you set the variable to null and never add any text to the variable!!! Data doesn't just magically appear in the variable.
Don't get me started about those stupid light bulbs. |