Class 2 (8/28/02) Wednesday
and Thursday JANUARY 16, 2003
Announcements:
Downloading the files for your first Java programming assignment. I will help you with this in the Wright 112 lab class.
(Note: For those of you anxious to try out your jGrasp and Java at home, if you already installed it, go ahead and download the three files now. The Project .gpj file and the Java .java file are small, but the .jar file (objectdraw.jar) is bigger and take up about 2/3 of the space on a high density floppy diskette. It will take a bit longer to download. (Be sure to RIGHT-MOUSE CLICK on the links to the three files).
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.
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);