Java的记录Navagation [英] Java Record Navagation

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

问题描述

您宝贵的帮助再次需要。我有以下的code在我读文件内容为每个文件。每个文件是有关个人的工作人员。在一个名为秀员工记录按钮的点击,我想显示在一个GUI的所有员工档案数据。但不是所有的人出现在一个我希望它有下一个navagation和previous像在MS Access?有任何想法吗。一个code吧?

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 navagation 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());
                        }
                    }
                }

所有你需要做的是让您可以使用它,然后导航数组列表时,前进/后退按钮pressed一些全局计数器。一旦按钮pressed,加载相应的文件(由计数器决定),并显示其内容。

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的记录Navagation的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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