Java记录导航 [英] Java Record Navigation

查看:50
本文介绍了Java记录导航的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您再次需要的宝贵帮助.我有以下代码,其中我正在读取每个文件的文件内容.每个文件都与一个员工相关.单击名为显示人员记录"的按钮后,我想在GUI中显示所有人员文件数据.但是,与其希望所有这些都出现在一个位置上,我不希望它具有下一个和上一个导航,例如在MS Access中?有任何想法吗.也许是一个代码?

your valuable help needed again. I have the following code in which i am reading file contents for each file. each file is related to an individual staff. On click of a button called "show staff record", i want to show all staff file data in a GUI. but instead of all them appearing at one i want it to have navigation next and previous like in MS Access? any ideas. a code perhaps?

/*********************Calculate Staff Balance***************************/   
public class calcBalanceListener implements ActionListener {
    public void actionPerformed(ActionEvent e) {

        FileReader fileReader = null;
        BufferedReader bufferedReader = null;
        try {
            File folder = new File("/register/");
           filePaths = new ArrayList<String>();
            if (folder.isDirectory()) {
                                for (File file : folder.listFiles()) {
                                    filePaths.add(file.getPath());
                                    }
            }

        }//end try

        catch (Exception f) {
            f.printStackTrace();
          } 

            callDetail();
            }}

/******************************************************************************/

/*************************************************************************/

public void callDetail() {


    File f = new File(filePaths.get(indexCounter));
    try{
        FileReader fileReader = new FileReader(f);
        BufferedReader bufferedReader = new BufferedReader(fileReader);
        String name = bufferedReader.readLine();
        int id = Integer.parseInt(bufferedReader.readLine());
        bufferedReader.readLine();
        String address = bufferedReader.readLine();
        int amount = Integer.parseInt(bufferedReader.readLine());
        bufferedReader.readLine();

        balanceFrame = new JFrame("Monthly Staff Balance");

            lID.setText("Staff ID: " + id);
            lname.setText("Staff ID: " + name);
            laddress.setText("Staff ID: " + address);
            lbalance.setText("Staff ID: " + amount);


            balanceFrame.add(lID);
            balanceFrame.add(lname);
            balanceFrame.add(laddress);
            balanceFrame.add(lbalance);

        bufferedReader.close();
        fileReader.close();

    }//end try
    catch(IOException z){

        z.printStackTrace();
    }   //end catch     


}

/***********************************************************************************************************/

/***************************************************************************************************/

推荐答案

您可能要做的是,在循环中而不是读取文件,您可能希望迭代并获取目录中所有文件的文件位置并将其地址放入数组列表中.

What you might do is that instead of reading the files, in your loop, you might want to iterate and obtain the file location of all the files in your directory and place their address inside an array list.

然后,您可以使用后退/前进按钮遍历阵列列表,每次根据当前在阵列列表中的位置加载文件.

You can then use the back/forward buttons to traverse the array list, each time loading the file according to which location you are currently in your array list.

List<String> filePaths = new ArrayList<String>();
if (folder.isDirectory()) {
                    for (File file : folder.listFiles()) {
                        filePaths.add(file.getPath());
                        }
                    }
                }

所有您需要做的就是拥有一些全局计数器,您可以使用它们在按下前进/后退按钮时浏览阵列列表.按下按钮后,加载适当的文件(由计数器确定)并显示其内容.

All you need to do is to have some global counter which you use to then navigate the array list when the forward/backward buttons are pressed. Once the button is pressed, load the appropriate file (determined by the counter) and display its content.

这篇关于Java记录导航的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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