Tuesday, July 24, 2007

Java: En Guard Update #3

A bug came up recently in the En Guard program that allowed a representative to save a record without filling in the information as to which rep took the call and what platform the problem occurred on.

The fix itself was rather simple as there is already a check to ensure that the other fields (contact name, number, subscriber number) are filled in.

if ((tempNumber.compareTo("") == 0) || (name.compareTo("") == 0) || (input.compareTo("") == 0) || (contact.compareTo("") == 0))
JOptionPane.showMessageDialog(recordPanel, "Please fill in all fields before saving record.", "Incomplete Record", JOptionPane.ERROR_MESSAGE);

In order to include the two additional fields the compound OR statement needed to be expanded.

if ((tempNumber.compareTo("") == 0) || (name.compareTo("") == 0) || (input.compareTo("") == 0) || (contact.compareTo("") == 0) || (platformBox.getSelectedIndex() == 0) || (repBox.getSelectedIndex() == 0))

PlatformBox and RepBox are the JComboBox variables for the two associated fields. If their currently selected option is the initial value of a blank space then the statements will be true and the record will not be saved.

Originally I thought I would need to create another variable or two to track when the selected index of either JComboBox changed, but the getSelectedIndex() method made things so much simpler. Hopefully no other changes will need to be made to the En Guard program as this is the only report of an issue within the past three months.

No comments: