简体   繁体   English

是否可以读取.txt文件的文件名并将其写入二进制树?

[英]Is it possible to read file names of .txt files and write them into binary tree?

I am writing a program that will stores information about students of two year groups. 我正在编写一个程序,该程序将存储有关两年制学生的信息。 There are 10 pieces of information for each student and in total there is about 120 students. 每个学生有10条信息,总共大约有120名学生。 I have decided to have a separate .txt file for each student for the program to read and transfer each file information into array on start up. 我决定为每个学生准备一个单独的.txt文件,以便程序在启动时读取并将每个文件信息传输到数组中。

However the problem I am facing is that there is a lot of different types of data manipulation: student profiles and JTable for each grade. 但是,我面临的问题是,有许多不同类型的数据操作:每个年级的学生资料和JTable The student profile I think is very straight forward, but in the JTable I will only need to access the first 2 and the last four pieces of information. 我认为学生资料非常简单,但是在JTable我只需要访问前2个和后4个信息即可。 I also need to have a JComboBox that will have the name of each student and gets updated as well when new students are added. 我还需要有一个JComboBox ,它具有每个学生的名字,并且在添加新学生时也会得到更新。

My questions are as followed: 我的问题如下:

  1. Is it possible to read file names of .txt files and write them into binary tree? 是否可以读取.txt文件的文件名并将其写入二进制树?
  2. How do I change the text in JLabel in program run-time? 如何在程序运行时更改JLabel中的文本? (This information comes from the arrays of each student.) (此信息来自每个学生的数组。)
  3. Is there a simpler way to do this? 有没有更简单的方法可以做到这一点?

Oh and I am using NetBeans, if that makes any difference. 哦,我正在使用NetBeans,如果有什么不同的话。

Needs urgent help. 需要紧急帮助。 Thank you! 谢谢!

  1. As follows 如下

    File folder = new File("D:/data");

    File[] files = folder.listFiles();

  2. Depending on the layout manager, to prevent on laying out the first window, and then having to short labels, maybe use a minimal size. 取决于布局管理器,为避免布置第一个窗口,然后不得不缩短标签,可能使用最小的尺寸。

    label.setText(...);

    label.setMinimalSize(new Dimension(..., ...));

  3. Yes, it might be simpler to use a database. 是的,使用数据库可能更简单。

Your approach has some clarity but implies writing a lot of code for maintaining lists, and writing several files back, and maintaining data integrity. 您的方法很清楚,但意味着编写大量代码来维护列表,回写几个文件以及维护数据完整性。 Coupled with swing GUI code that is an effort. 再加上挥杆的GUI代码,这是一种努力。

In every case make sure you make backups, and have test data and such. 在每种情况下,请确保进行备份,并具有测试数据等。 Separate Model (the data) from the View (GUI). 从视图(GUI)分离模型(数据)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM