1. As usual, Java is very slow to recognize an onMouseClick() event, so keep trying the Reset button until you succeed. I should have used an onMouseRelease or onMousePress instead!

  2. How many local variables does the entire class have now? Count them again, the answer is different than this morning's handout. Need to review material on LOCAL, PIV and Parameters, the three types of variables you see in class definitions.

  3. Here is the Java code...
    // Wednesday, September 25th, 2002 example for 810:061
    // Study in conjunction with Big Java book pages 90-92 Purse.java
    // Purse class.  The code here will be used along with  quarters,
    // dimes and nickels "buttons" to add coins to the coin purse.
    
    import objectdraw.*;
    import java.awt.*;
    
    public class CoinPurseDemo extends WindowController
    {
       private Text t1;
       private FilledRect r,
                          reset;
    
       private boolean settingValue;
    
       private int numberOfCoins,
                   previousX;
     
    
       public void begin()
       {
          String message;
    
          message = "Drag inside the purple to change the counter's count.";
    
          t1 = new Text("0", 20, 50, canvas);
    		t1.setFontSize(30);
          t1.setColor( Color.blue );
    
          new Text(message, 20, 120, canvas).setFontSize(14);
    
          r = new FilledRect(20, 100, 335, 20, canvas);
          r.setColor( Color.magenta );
    
          numberOfCoins = 0;
    
       
          reset = new FilledRect(120, 20, 150, 25, canvas);
          reset.setColor( Color.yellow );
          new FramedRect(120, 20, 150, 25, canvas);
    
          Text t = new Text("RESET COUNTER", 145, 25, canvas);
          t.setColor( Color.blue );      
          t.setBold();
       }
    
       public void onMousePress(Location point)
       {
          settingValue = r.contains(point);
          previousX = (int) point.getX();
       }
    
       public void onMouseClick(Location point)
       {
          if ( reset.contains(point) )
             resetCounts();
       }
    
       public void onMouseDrag(Location point)
       {
          if ( settingValue  && r.contains(point) )
          {
             int difference = (int) point.getX() - previousX;
    
             if (difference >= 10)
             {
                numberOfCoins++;
                previousX = (int) point.getX();    
             }     
             else if (-difference >= 10)
             {
                if (numberOfCoins > 0)
                   numberOfCoins--;
                previousX = (int) point.getX();
             }
    
             t1.setText( numberOfCoins );
          }
       }   
    
       private void resetCounts()
       {
          t1.setText( "0" );
          numberOfCoins = 0;
       }
    }
    
  4. More later... Please study this carefully!