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.
Rob Camick wrote:Look at your code:
You assign null to the line variable.
Rob Camick wrote:Well you can use the JList.getSelectedValue() method which will get the data from the DefaultListModel for you.
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.
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.
Campbell Ritchie wrote:Try changing all the commas in the input file to spaces.
Guillermo Ishi wrote:If you put all the cards in an arraylist you can do this - choose a random number between 0 and its size-1 (51 to start with). Use that random number as an index into the arraylist. That will be the card you are dealing. Remove the element with that index from the arraylist from from the arraylist. That gives you a new upper bound for the next random number. The arraylist elements can be a Card object with suit and value fields.
Stephan van Hulst wrote: