The following app is designed to play music using javax.sound.midi. It has three menu items, new, save, and load. New and save work as expected, but load does not. The load menu item has an ActionListener, LoadMenuListener. LoadMenuListener's actionPerformed() method opens the JFileChooser and passes the selected file to loadFile(File file). In loadFile(File file), a BufferedReader is chained to a FileReader(file). Then, the BufferedReader reads the only line in the file. This line contains 0's and 1's separated by commas. String.split(",") is called on the line and the result is stored as an array of Strings. Then, the program steps through each element and does an if/else/if:
based on the results, it sets the element of checkBoxList in question (a JCheckBox) to either true or false.
That is what SHOULD happen. What REALLY happens however, is that it does not change the state of any JCheckBox in checkBoxList. It give's no run-time errors.
You can't compare the contents of Strings using the "==" operator; this operator returns true if and only if two Strings represent the same physical object in memory, and a String read from a file will never be the same physical object as a literal embedded in a program (like your "0" and "1"). Instead, you want to compare the contents of the Strings; for this you must use the equals() method:
Beware of NullPointerExceptions -- you'll get one with this code if result[cellNum] is ever null.