
The Listener associated with the JList was copied along with the JList component itself and only small modifications were required to allow it to function properly. The JButton Listener however had to be created from scratch. Once the button was pressed several things needed to happen. First I needed to populate an array of file names for those currently present in the data directory. Originally I had gone with a brute force method since all of the file names are numbers ranging from 1 to 2.5 million. I had a For loop checking which files existed and if they did adding them to the JList component.
Obviously this took quite a bit of time to complete and slowed down the program considerably, enough so that it actually crashed the program on more than one occasion. Therefore a rewrite of the method (called by the Listener) was required. In reviewing the File Class I noticed a nice method named list() that would output a String array of the files present in a given directory. Exactly what I was looking for. Then calling a length method on the created arrays produced the exact number of files present so the slots used in the array is known and an exception isn't caused by trying to access a nonexistent array slot.
This search method was much faster than the previous one and does not crash the program at all, which was a nice bonus. Now a few other minor details need to be completed to have this version of En Guard finished. Specifically I want to add a log in dialogue to the program that will register which representative is using that version. This will allow me to auto populate the Submitted By field as well as save the user's skin color preference.
No comments:
Post a Comment