Home
The objectdraw Library
Sample Chapters
Programming Examples
Sample Lab Exercises
Instructor's Resources
Visit Prentice-Hall

 JAVA: An Eventful Approach
 

Our approach to introducing programming using Java depends on a library we have designed which provides:

  • simplified support for handling mouse events,
  • a collection of classes for displaying simple drawings that provides a more object-oriented programming interface than the standard Java Graphics class, and
  • facilities to simplify the management of multiple Threads.

In designing this library we were very conscious of the fact that the advantages of using a library are offset by the disadvantage of hiding portions of "real Java" from students. Accordingly, we carefully limited the scope of our library. The event-handling features of our library are only used to enable students to work with simple mouse events in the very first weeks of the course. After that, students are introduced to standard Java GUI components and standard Java event handling. We use our graphics classes throughout the course, but their design deliberately mimics the methods provided by the standard Graphics class. Almost all of the Thread management functions we provide are transparent to the students.

A detailed description of the features of our objectdraw library is available on our website in Javadoc format, and in compressed form for download. See the notes for information on converting from the older AWT version of the library.

The current version of our library is available for download:

  • Objectdraw version 1.1.2 jar file: objectdrawV1.1.2.jar. Right-click (on Windows) or control click (on Mac) to download the jar file. Save it as objectdraw.jar even if your browser attempts to add a ".zip" suffix.

  • When using newer versions of the objectdraw library (version 1.1 and beyond), the static method Controller.getVersion() will return a string describing which version of the library is being used.
Click below for instructions on how to incorporate such a .jar file into a project created using a variety of Java IDE's. To download a .rtf file of the instructions for a particular IDE, click on the appropriate link. For those teaching AP CS courses, setting up your IDE to use the objectdraw library is exactly like setting it up to use the MBS library.

Information on using objectdraw from JCreator is available from Dave Wittry.

Using objectdraw with applications rather than applets

There is a simple way of using objectdraw with applications that is new with version 1.1 and later of the objectdraw library. Under these version of objectdraw, you can run extensions of WindowController (or Controller) as applications by using a new method named startController. This method is included in the Controller class (and thus is inherited by WindowController).

To turn what would have been an applet into a program that can also be run as an application, simply add the following method to your class that extends Controller or WindowController:

public static void main(String[] args) { 
   new MyClassName().startController(400,400); 
} 
In the above, MyClassName is a placeholder for the name of the class extending Controller, while the parameters (400,400) specify the size of the window desired.

Section 19.3 of the text explains how to write applications when using files, and Appendix D.6 discusses how to modify applets to be run as applications in standard Java. However, the advantage of the above method is that it requires the least amount of change for using the programs included in the text. Thus if your environment makes it difficult to run applets, we highly recommend that you follow the technique explained above.