This is a modified version of the objectdraw
library originally created by Kim Bruce, Andrea Danyluk, and Thomas Murtagh. That library was used in programming classes at Williams college, and in the textbook Java: an Eventful Approach. The purpose of the library is to simplify the use of graphical objects and events so that they will be accessible to introductory students. The original library and more information are available at:
http://eventfuljava.cs.williams.edu/
This version of the library was created by Russell Zahniser, a teacher in the Boston Public Schools, for use in introductory Java classes there. It contains several improvements over the original library:- To make it easier to use the book's technique of teaching about creating and using objects before variables are introduced, color has been made an optional parameter in most constructors for graphical objects. This introduces a useful example of constructing "compound" objects made up of others:
new FilledOval(new Location(0, 0), new Location(100, 100), new Color(150, 0, 255), canvas);
Introducing the use of constructors like this makes it easier for students to grasp what is going on when later a variable takes the place of one of those objects.
- For the same reason, the
toString()
methods of the various objects have been altered to print out Java code describing how that object could be constructed.
- To make it easier to use the book's technique of introducing the
int
type early on but waiting until later to introduce double
, the return types of most methods that previously returned double
have been changed to int
. Where precision is required, there is usually another version of the same method that returns a double
; so, for example, Location
has both getX()
and getDoubleX()
.
- Several changes have been made to improve the appearance of graphics created with the library. Most noticeably, graphics and text are now antialiased.
- A key event system has been added that uses the same simplicity as the mouse event system. Now, if a program should react when a key is pressed, its
WindowController
can simply provide a method like this:
public void onSpacePress()
- The
Text
class has been extensively modified to make it more natural to use in labeling parts of a sketch:- It can cover multiple lines, separated by a "\n" line break character
- It can be aligned to the left, right, or center, and similarly to the top, bottom, or center.
- Decimal values displayed in a
Text
object are limited to four decimal places. This avoids the common problem of a double value appearing with a long string of 9's or 0's due to the limits of double precision.
- Text can be wrapped to another object, called the basis of the text. So, for example, you can make text line up along a
Line
object, or wrap to fit within a Oval
object. Any other shape can be used as the basis.
- Several
Text
objects, each with a different font and color, can be chained together to produce a single string of text whose style varies.
- A new
Turtle
class has been introduced for drawing turtle graphics. This is a good way to introduce ideas of looping and recursion.
- Beginning students often try to move and object with code like this:
object.getLocation().translate(10, 20);
After long deliberation and going back and forth on the issue several times, I decided to make the Location
returned from getLocation()
be capable of moving the object. It would have been better, in my view, if Location
were immutable and translate()
simply created a new Location
, but with the translate()
method there, it ought to work as a person would expect. There is an offset()
method in Location
that simply returns a new Location
offset from the position of the original.
- Animating things with
ActiveObject
is complicated because of the need to create a separate class for every type of animation. Also, it suffers from graphical artifacts due to the problems of manipulating UI elements from a thread other than the event dispatch thread. The new class EventTimer
can simply call any public method of an object, with a fixed set of arguments, on a schedule, on the event dispatch thread.
- The
Animation
class has no real pedagogical value, but adds some flair to student projects. It can display a variety of particle-based animated effects around any object on the screen.
- For creating network games, there is now a
Network
class that allows students to have their program send and receive messages over a LAN simply by implementing two interfaces, one for the client and one for the server.
- Various bug fixes have been made.
This new version of ObjectDraw is entirely backwards-compatible with the old version. So, any code in the book, or any code that works with the old library, will also work with the new one, although that code will have to be compiled again.
There is an alternate form of this documentation that groups its descriptions of the library on the basis of tasks you might want to accomplish with it, rather than individual classes. You can access that documentation, and the high school class that I designed around this book and library, from my website:
http://www.zahniser.net/~russell/computer/