0

I am currently in a Java course. We are writing an application to store an inputted name and phone number in an arraylist. When an add contact button is pressed it should return the data into two separate JTextFields which is stored in a class and can be scrolled through. I am having trouble getting the data to return to the Textfields. Thanks

    private int position = 0;

     private void addContactJButtonActionPerformed(java.awt.event.ActionEvent evt) {                                                  
    setContact();
   newContact = new Contact(nameJTextField.getText(),
           Integer.parseInt(numberJTextField.getText()));

  ContactsArrayList.add(newContact);
  position = ContactsArrayList.size() - 1;
  loadContact();
}

    public void setContact()
{
    newContact.setName(nameJTextField.getText());
    newContact.setNumber(Integer.parseInt(numberJTextField.getText()));

}

    public void loadContact()
{
    newContact = (Contact) ContactsArrayList.get(position);

    storedNameJTextField.setText(newContact.getName());
    storedNumberJTextField.setText(String.valueOf(newContact.getNumber()));
}
  • The code I have tried – Matt Parker Oct 19 '13 at 17:53
  • Please add the code you've written so far. You'll get better answers that way. – Jason Braucht Oct 19 '13 at 17:54
  • If you have reference to the textfields you do it like so, yourTextField.setText("the text"); – melc Oct 19 '13 at 17:57
  • You say you're having trouble... What exactly is the trouble you're having? By the way, you should probably read up about [why you shouldn't use an Integer to represent a phone number](http://stackoverflow.com/questions/3483156/whats-the-right-way-to-represent-phone-numbers) – wakjah Oct 19 '13 at 18:48
  • I am having trouble because I guess im not sure of the best way to do what I am trying to do. I am trying to store the information in nameJTextField and numberJTextField into a class, then return that information ino storedNameJTextField and storedNumberJTextField respectively so that th information can be navigated through using next and back buttons. – Matt Parker Oct 19 '13 at 18:59

0 Answers0