address book next and previous buttons

后端 未结 1 1079
没有蜡笔的小新
没有蜡笔的小新 2020-12-22 12:14

I\'m making an address book and I need to cycle through my contacts. The contacts are imported from file and are read into the JTextFields as so:

name

1条回答
  •  北海茫月
    2020-12-22 12:34

    In your importContacts() method

    you do :

     txtName.setText(Name.get(0));
     txtPhone.setText(Phone.get(0));
     txtMobile.setText(Mobile.get(0));
     txtAddress.setText(Address.get(0));
    

    instead of .get(0) I think it should be .get(index) according to your code

    --Edit--

    or to avoid re-importing your contact here what your previous() method should be :

    public void Previous()
                {
                        if (index > 0)
                        {
                                index--;
                        }
                        txtName.setText(Name.get(index));
                        txtPhone.setText(Phone.get(index));
                        txtMobile.setText(Mobile.get(index));
                        txtAddress.setText(Address.get(index));
    
                }
    
      public void Next()
                {
                        if(index < temp.size() - 1){
                           index++;
                         }
                        txtName.setText(Name.get(index));
                        txtPhone.setText(Phone.get(index));
                        txtMobile.setText(Mobile.get(index));
                        txtAddress.setText(Address.get(index));
    
                }
    

    -Final edit, code source availabe at pastebin

    0 讨论(0)
提交回复
热议问题