Friday, November 23, 2012

Over thinking a problem


There is a principal called KISS which stands for Keep It Simple Stupid. It is meant to remind you to try to keep things from getting to complicated. I was doing a exercise from the book "Head first Java" which involved making a "BeatBox" which plays Midi sounds. You have 256 check boxes to choose from. There were two features not added to the example. One was clear boxes and two was being able to choose the name of the file to save or open. After a bit of work and research I was able to do part two. Part one I had already did but with bad coding and I knew there had to be a better way.

First try:// here I just wanted to get it done
public class MyClearListener implements ActionListener {
public void actionPerformed(ActionEvent a) {
                      sequencer.stop();// stops Midi playing
                      theFrame.dispose();// remove old window
                      buildGUI();// rebuilds whole window to clear checkboxes
               }
        }

Second try://here is where I was making it more complicated
public class MyClearListener implements ActionListener {
public void actionPerformed(ActionEvent a) {
     for (int i = 0; i < 256; i++) {
JCheckBox check = checkboxList.get(i);// complicated
if (check.isSelected()) {
check.setSelected(false);
} else {// this part is not needed the checkBox is already false
check.setSelected(false);
}
     }
               }
       }

Third try:
public class MyClearListener implements ActionListener {
public void actionPerformed(ActionEvent a) {
for (int i = 0; i < 256; i++) {
                               checkboxList.get(i).setSelected(false);
                        }
               }
        }

10,000 hour to mastery.
10,000 - 326.25 = 9673.75 hours left

Sunday, November 11, 2012

Slowing down

 


  Because of life events I have not had much time to study / practice  java programming but hopefully I can pick it up.

10,000 hour to mastery.
10,000 - 320.5 = 9679.5 hours left