1

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!

kleopatra
  • 51,061
  • 28
  • 99
  • 211
  • 1. yes. 2. `label.setText(array[i])`. – JB Nizet Mar 09 '13 at 22:57
  • Is there a reason you want a text file per person? If there is only 10 items per user, would CSV be usable? Should be easier than managing all of those files – Robert Mar 09 '13 at 22:59
  • This has already been asked and answered [here](http://stackoverflow.com/questions/1384947/java-find-txt-files-in-specified-folder). – gibertoni Mar 09 '13 at 23:15

1 Answers1

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

Joop Eggen
  • 107,315
  • 7
  • 83
  • 138
  • For the label dilemma, i have an issue with NetBeans, as the labels that it makes in InitComponents() are private, and i don't know of any way to change that. Is there a way to change that, or another path around that setting? – Vincent Frodont Mar 10 '13 at 06:31
  • Make a `public void setLabel(String s)` that can be called from outside and maybe do a `repaint()`. – Joop Eggen Mar 10 '13 at 20:58