简体   繁体   中英

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. 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.

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. 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. 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.

My questions are as followed:

  1. Is it possible to read file names of .txt files and write them into binary tree?
  2. How do I change the text in JLabel in program run-time? (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.

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.

In every case make sure you make backups, and have test data and such. Separate Model (the data) from the View (GUI).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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