CS51 - Fall 2009 - Lecture 25

  • Show DrawingPanelWithShapeArray demo
       - Recall, the key private member variables
          - private int MAX_OBJECTS = 25;
          - private int SIZE = 100; // dimensions of the objects
          - private DrawableInterface[] shapes = new DrawableInterface[MAX_OBJECTS];
       - Recall, our onMousePress method has four options
          - add a new item
          - move an item
          - recolor the item
          - delete an item
       - How do we add a new item?
          - figure out the shape from the menu and create a new shape
          - figure out the color from the menu and set color
          - add to our shapes array
       - How do we implement move?
          - need to figure out which shape we've clicked on
             - write a function int getIndexOf(Location point)
             - iterates through our list and calls .contains() on the points
          - now, that we know what we've clicked on, how do we move it?
             - private DrawableInterface selected;
             - set selected = null at beginning of onMousePress
             - if it's a move, set selected = the object selected
             - onMouseDrag can move the object pointed to by selected
          - how do we deal with overlapping shapes?
             - if we click on an overlapping spot, went to move the one on front
             - when we're adding things, how is this order preserved?
                - elements later in the list are more "in front" than earlier
                - search the array from the back forward
          - When we move an item, we need to preserve this functionality
             - move the item to the front of the canvas
             - move the item to the back of the list and shift everything else down
             - how can we implement this?
                - remove the item we want to move to the end
                   - removeEltWithIndex(int index)
                - then put it at the end
       - How do we implement Recolor? (should be easy now)
          - getIndexOf(point)
          - recolor that objects
       - How do we implement delete? (should be easy now)
          - getIndexOf(point)
          - remove the object from the canvas
          - removeEltWithIndex()

  • Show textStatDebug demo

  • Debugging functionality
       - set breakpoints
       - step over
       - step into
       - continue

  • Other misc. array things
       - What happens here?
          int[] numbers = new array[10];
          int currentIndex = 0;
          ...
          currentIndex = 10;
          numbers[currentIndex]++;
          
          - ArrayOutOfBounds exception