地址簿下一个和上一个按钮 [英] address book next and previous buttons

查看:111
本文介绍了地址簿下一个和上一个按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在制作一本地址簿,我需要循环浏览我的联系人。联系人从文件导入并按原样读入 JTextField

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

手机

手机

地址

name
phone
mobile
address

我该怎么做?

我试过,它运行但按钮什么都不做。

I've tried, it runs but the buttons do nothing.

编辑:现在使用这个:

           public void importContacts() 
           {
        try 
            {

             BufferedReader infoReader = new BufferedReader(new FileReader("../files/example.txt"));
            txtName   .setText(readLine(infoReader));
        txtPhone  .setText(readLine(infoReader));
        txtMobile .setText(readLine(infoReader));
        txtAddress.setText(readLine(infoReader));

            } 
            catch (IOException ioe) 
            {

            JOptionPane.showMessageDialog(null, ioe.getMessage());
        }

}

推荐答案

在你的 importContacts()方法

你这样做:

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

而不是 .get(0) I认为它应该是 .get(index)根据你的代码

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

- 编辑 -

或者为了避免在此处重新导入您的联系人,您的上一个()方法应该是:

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));

            }

- 最终编辑,代码来源 pastebin

-Final edit, code source availabe at pastebin

这篇关于地址簿下一个和上一个按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆