Thursday, October 30, 2008

Java: En Guard Update #6

Beyond the search feature there were a few other minor changes I wanted to make to the En Guard program. First off the "Contact Info" JTextField is currently a required field to submit a new record. This field turned out to be less useful than I had intended so I am making it an optional field instead. At first I thought I would need to alter the code checking which fields are filled as well as the code that opens and saves the records. As it turns out none of this was necessary. All I needed to do was set the text of the JTextField to be a space character. By doing this the field is technically "filled" and saving/opening records works just as it did before. Good reminder to always look for the simple solution first and then work towards more complex resolutions.

The second feature I wanted to work on was making the skin chooser a bit more viable. Currently it works great to change the background color of the application, however whenever the app is closed it reverts back to the original color. This can get tedious to change such information every time the program is opened. Therefore I added a log in to the program that forces the user to choose a representative name before gaining access. This method is called before the properties of the JFrame are set.

JOptionPane.showConfirmDialog(aFrame, loginPanel, "Select Name", JOptionPane.DEFAULT_OPTION, JOptionPane.PLAIN_MESSAGE);
loginIndex = loginBox.getSelectedIndex();

The log in sets the loginIndex variable to the index corresponding to the rep's name. This information is then used to designate the file name that the program will need to open in order to determine what color to set the background to. Each rep has their own text file containing their color information, such as:

150
200
250

The file is then opened and each line of text assigned to the background color variables red, green and blue. Once done the SetBackground() method is called to change all of the JPanel's color accordingly. The text file will be updated whenever the ColorChanger() method is called as well, to ensure that the next time the program is opened it does so with the most recently selected color combination. As an added bonus, as the rep's name is being stored for this process, the Entered By field is automatically populated with the rep's name once the program is opened.

No comments: