Lecture 2 (8/28/02)

Announcements:

Topics for the day:

Using objectdraw graphics primitives

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. Simplest Box - uses an anonymous object

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!!!

FilledRect box;

2) Constructs an object using "new" and assign the reference ot the object

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

3) Call an object's methods using its name

box.setColor(Color.red);

Demo 2. Colored Box - uses an anonymous object

Components of Java Program

Three types of comments:

/* This is a

multiple-line comment.

*/

// This is a single line comment

/** This is a javadoc comment that can be used to

automatically generate html documentation of the program.

*/

"import" statements - these specify in what package we need to look for classes used in this program

"class" declarations - to use the objectdraw package you need to create a class that extends WindowController (which is pretty much like an Applet)

Method declaration - within a class you can create methods that are actions that objects of the class can perform

In the example above, "begin" was the only method. "begin" is a special WindowController method that automatically gets performed once when the program starts executing.