Class 2 (8/28/02) Wednesday and Thursday JANUARY 16, 2003

Announcements:

Topics for the day:

Graphics primitives - Williams College textbook objectdraw library

Basic entities we can draw are:

   
      FramedRect, FilledRect
      FramedOval, FilledOval
      Text
      Line

How we build these:

   new FramedRect(10, 10, 40, 60, canvas);

   new Line(x1, y1, x2, y2, canvas);

   new Text("hello there", x, y, canvas);

Demo 1. Rectangle and nested red square - uses both anonymous objects and a named objects.

Naming

OK, now say we want to write a program that has a red box. We need a name so that we can call methods associated with the object.

objectName.methodName( parameters );

Steps:

1) Declaration of object name - only save memory for a reference/pointer. No object created yet!!!

e.g., FilledRect box;

2) Constructs an object using "new"

e.g., box = new FilledRect (100, 200, 150, 150, canvas);

3) Call an object's methods using its name

box.setColor(Color.red);