Chapter one (Williams manuscript) example output and Java code


To be handed out Tuesday, January 21st in the hands-on class in Wright 112 lab. (See my office door, or see me in Wright 106 to get a copy of this handout ahead of time, if you wish).

Here is the output of my program, shown exactly as it would look using jGrasp at home or in the Wright Hall labs:

// Written by Mark Jacobson on Wednesday, August 28th, 2002.

// Study this as you carefully read, reread, review and refer to 
// the library purchased packet - 

// Everything here is a review of chapter one of the Williams College 
// manuscript.  Note that the Williams College text urges you to
// NOT concern yourself with some portions of the syntax at all,
// but think of them as magical incantations, like abbra cadabra.
//                      --------------------
// You need to just imitate and recite these magical incantations
// for your first program, without worrying about the why or what 
// they mean.  That will come later, when you are ready, after more
// groundwork is laid down and experience is gained.

import objectdraw.*;
import java.awt.*;

public class SimplestBox extends WindowController {

   public void begin() {
      new FilledRect(50, 100, 35, 105, canvas);

      FilledRect redRect = new FilledRect(60, 145, 15, 15, canvas);
      redRect.setColor(Color.red);

      new Text("Written by Mark Jacobson", 50, 220, canvas);

      Text dateMessage = new Text("810:061 demo on August 28th, 2002", 
                                   50, 250, canvas);
      dateMessage.setColor(Color.blue);

      Line myRuler1, myRuler2;

      myRuler1 = new Line(50, 240, 189, 240, canvas);
      myRuler2 = new Line(50, 241, 189, 241, canvas);

      myRuler1.setColor(Color.green);
      myRuler2.setColor(Color.green);
   }
}

Summary of important points of the above example, with answers to any questions that arose during class or afterwards by email. Clarifications of and elaborations of the program, especially helpful for preparing you for the first hands-on class on Friday, August 30th.
  1. Here are the objectdraw statements that were introduced today in class:
    6 different Constructors for Graphic Objects
                ------------
    
        new Line( startX, startY, endX, endY, canvas); 
    
        new FramedRect( x, y, width, height, canvas); 
        new FilledRect( x, y, width, height, canvas); 
    
        new FramedOval( x, y, width, height, canvas); 
        new FilledOval( x, y, width, height, canvas); 
     
        new Text( "some message", x, y, canvas); 
    
    This is the one METHOD that was shown.     someColor could be Color.blue
                    ------                        or Color.red or Color.green.
        someObject.setColor( someColor ); 
    
  2. Exercise: The last 5 statements in this program could be replaced by two statements, and produce exactly the same output. Think about how you might do that. There is almost always more than one way to solve a problem, which is what makes programming so creative and fun. See the solution to exercise.

  3. Drawing a W on the screen. How would you do that with the Line contstructor? Here is a snapshot of what the desired W output could look like.