© 2000-2003 A-Square, Inc. Cambridge, MA
Uploaded to www.rart.com/JavaIntro0301/ on Jan. 31, 2003
Lecture Notes for JICC7
The Introduction to Java Exercises Displayed and Commented Briefly
Exercise 0. Welcome
Provided to show the idea that a Java applet can display buttons with meaning on the Internet. Difference between Browser and Appletviewer.
Exercise 1. Welcome to Introductory Java
Shows a complete applet with doublebuffering and executing in a way to control timing of the animation. A fairly long program.
Introduction to Object Oriented Programming. We separate the functionality of the ASquareLogo from the rest of the program and embody the logo properties in an abstract class Logo. Functionally we get an applet equivalent to the one of Exercise1. However, it is now easy to create a new banner for another logo.
Exercise 2a. ASquareLogo
The code of Exercise 1 is split in three classes, the abstract class Logo, ASquareLogo that extends Logo and the applet Banner2a. Functionally equivalent to Banner of Exercise 1.
Exercise 2b. IEEELogo
We retain Logo unmodified but derive a new class IEEELogo that extends Logo. While ASquareLogo used the simple drawing routines from AWT to render the logo, IEEELogo imports a .gif file with a picture. The Banner2b has been modified in 3 places where it refers to the class derived from Logo but is otherwise identical to Banner2a. This exercise also serves to introduce the security restrictions for an applet. Banner2b can not be displayed over the Internet since IEEELogo imports a file, the IEEE logo, as a .gif-file, which the browser does not allow.
These exercises introduce the Rart development and execution environment using the Banner of previous exercises as example. The abstract Logo class is almost the same as for Exercise 2, except that the import of any file now is handled by the Rart execution environment, the rartrunner. We also provide, in the universe, information about the Java operating environment. The Banner universe is displayed in the RRL rartrunner, suitable for including of the universe on a web page, but with limited facility for observer interaction.
Exercise 3a. A Single Logo
The Banner3a universe executing as an applet looks exactly the same as the earlier Banner applets. An A Square logo is floating behind some text.
Exercise 3b. Multiple Logos
Demonstrating the flexibility of the execution environment, we show how with a few lines of code we can have several logos floating around, and the number of logos modifiable by the observer. We also, when executing the Banner universe in the appletviewer, can see how the rartrunner automatically adjusts to a modified size of the applet window.
Exercise 3c. Timing
Functionally Banner2c behaves the same as Banner2b. However, we also provide some timing information related to the execution of the cycle loop of the universe. Timing of the freqency of frames regardless of platform speed is another of the functions of the rartrunner.
Exercise 3d. Multiple kinds of Logos
We now introduce also the IEEE logo of Exercise 2b in the Banner3d universe. This time, the rartrunner, which executes as an applet, handles the import of the .gif file and the universe can be displayed over the Internet without security problems.
The Eggs universe is one of the first real universes. It meets the criterium of being visually interesting and never repeating itself or repeating itself with very small probability. It is displayed here in the RRlet rartrunner as a full blown applet with the observer able to modify all parameters through a series of dialog boxes initiated with a long mouseclick.
Exercise 4a. Eggs Default, Simple Eggs
The Eggs universe is displayed. We also show how the applet tag can be used to give other than default values to the parameters of the universe.
Exercise 4b. Rectangles
By modifying one line of code we change the look of the Eggs universe that now becomes a "rectangles" universe.
In Exercises 4c - 4e, we go through the steps of modifying the Eggs universe to make it into what we call the Planes universe where rectangular planes appear to rotate around a vertical center axis. The intent is to show methodology. In the end we have learned important lessons about programming a Rart universe and also gained considerable insight into shades of color available in Java.
Exercise 4c. Simple Planes
The planes vary vertically and horisontally and seem to grow and diminish rsther than rotate.
Exercise 4d. Add Shadowing
Change default colors, add shading. Looks better.
Exercise 4e. Add More Stuff
All planes same proportion; add design on plane; add shadow from adjustable position of light source. Looks good, but not spectacular.
We now show two more Rart universes executing in an application environment under the rartrunner RR11 which gives the observer the ability to save and print views of the universe. The observer modifies parameters through a popup menu.
Note: For the benefit of those who are evaluating the tutorial over the Internet, we display the universes executing under the RRlet rartrunner. However, the observer must realize that the application environment with arbitrary screensize, simpler popup menu interface, tha ability to switch between available universes, and the ability to freeze and print should make the experience of observing Rart universes much more rewarding.
Exercise 5a. Lines universe
This is close to the original Lines universe as programmed for the Macintosh around 1987. The screen was the small black and white Mac-screen and the program written in MS QuickBasic for the Mac, not easily portable to anything else.
Exercise 5b. Lines universe enhanced
We add the ability to select color combinations.Actually Lines of Exercise 5a and 5b look the same since you have to go into the modification of parameters to see the difference. On the Internet we actually provide links to the same Lines universe.
Exercise 5c. Polygons universe
The EndPoint class provides the anchor for the endpoints in the Lines universe. In the Polygons universe, the number of endpoints is a parameter under observer control. The polygon that results from the connection of all the endpoints provides the interest of this universe.
Exercise 5d. Flakes universe
In the Flakes universe the mechanism for building an ordinary snowflake is simulated. This universe shows more perhaps than the other universes on display, how randomness and order interact to create surprising variations on a simple theme. The Flakes universe uses a class rPoint60, which takes care of much of the geometry of the rendering of a flake.
Exercise 5e. Greeting Card with Flakes
As a final example of a Rart universe the 2002 Christmas card, Xmas02, shows some further development of the Flakes universe as well as how text files can be input to personalize this universe without recompilation. It may be interesting to note that the greeting card is more object oriented with all the flake properties collected in a Flake class. The Flake car uses a class rP60ME, functionaly equivalent to rPoint60, but programmed in all integer arithmetic in anticipation of a move to J2ME, the Java version used for the programming of small handheld devices such as cell phones.