CSE 341 -- Programming Languages
Department of Computer Science and Engineering, University of Washington
Steve Tanimoto (instructor) and Jeremy Baer (teaching assistant).
Assignment J2Version 1.3 of April 12 (subject to minor change)
See changes in blue as of April 9
and in green as of April 10. See description of
4 general options at end of page (added April 12).
Java In DepthDue date and time: Friday, April 16, 1999, at 12:30 (at the beginning of class).
Instructions for turning in your work will be given later.
Instructions: Implement a Java program (support both App and
Applet modes) that lets the users draw objects and
then graphically specify animations involving thoses objects. Implement all of the "core" functionality described below, and then implement at least 2 of the extensions. Finally, if you wish, implement features of your own.
Teamwork: You are encouraged to perform this assignment in teams of two people. Each member of a team is accountable for understanding the entire program. More is expected from two-person teams than from individuals. Team projects must include a description, in the comments at the beginning of the main Java source file, of who wrote each major component of the program.
1. User can press on a button to create a new animation object and a drawing canvas or frame appears [CHANGED TO OPTIONAL: along with some drawing controls, including a tool to change the brush size and a tool to select a color for drawing]. [CHANGED TO OPTIONAL: Once the user has drawn the object, s/he can click on an "Accept" button that puts the drawing canvas away and saves the new object somewhere]. The user should then be able to press on the button again to create a new object and have that one saved, too, and so build up a collection of objects.
2. User can press a button ("Arrange Animation") to open an animation frame or panel. [ALTERNATIVELY, an animation panel can show up automatically when the program is started.] A list, toolbar or other presentation of the user's animation objects should appear on the side. The user should then be able to click on one of the objects and click on the animation frame to place an instance of it there.[UPDATE: YOU DON'T HAVE TO SUPPORT MULTIPLE INSTANCES OF EACH DRAWING] [OR IF YOU WISH, simply keep each drawing canvas open and put a button next to it so the user can select that drawing to put on the animation canvas.]
3. User can specify a "trajectory" for the animation object on the animation frame the user can do this by clicking on a button called "Draw Trajectory" [BUTTON CHANGED TO OPTIONAL: . THAT IS, IT'S OK TO LET THE USER JUST DRAW THE TRAJECTORY ON THE ANIMATION CANVAS WITHOUT CLICKING ON A DRAW TRAJECTORY BUTTON]. Then the user drags the mouse in the animation frame to tell the system how the object is supposed to move. As soon as the user releases the mouse, that is the end of the motion.
4. User can press a button marked "Go!" which starts the animation. During the animation, each object that the user has placed on the animation frame begins at the location where it was placed, and then it moves along the trajectory given by the user.
Many aspects of the core program are up to you: the style of the drawing permitted for the objects, the timing of the motions in the animation, etc. The main points are to have: user-drawn objects, user-drawn trajectories, any number of objects (user gets to decide), any number of instances of objects participating in the animation (user gets to decide).
Use at least one separate thread for running the animation.
Extensions: (Teams should implement at least 2 out of 6)
1. Implement synchronization of the objects' motion so that they all end up stopping at the ends of their trajectories at the same time.
2. Provide a way for the objects to keep moving after they reach the end of the trajectories given by the user.
3. Provide collision detection among the objects and make something interesting happen when objects collide, such as changing trajectories or appearances.
4. Provide a way for the user to draw a graph of size versus time and attach that behavior to an object so that it grows and shrinks during the animation according to what the user drew.
5. Provide some means for the user to interact with the objects during the animation, such as by clicking on them or by operating a paddle and having them react in some interesting manner.
6. Provide a way for an animation object to change into another one
during the animation, so that its appearance can change.
Programming style: Define your classes carefully. Comment your code. Explain (in your comments) where you are using inheritance. Explain (in your comments) where you are providing a method that overrides the one that would be inherited. Choose identifier names carefully. Use appropriate indentation and other formatting. Make your code easy to read and understand.
Here is an applet that shows just one possible way to satisfy the minimum requirements. This requires a JDK1.1 compatible browser. For example, it works under Microsoft Internet Explorer 5.0 with the Java extension. Instructions for using the applet: click on "Create Object" for each animation object you wish to create. The maximum number is currently limited by the width of the applet, and the fact that the panel in which these objects appear is laid out with FlowLayout. Make your drawing right on the small canvas for each animation object. Then you may draw a trajectory for it by selecting the object with its "Select Me!" button and then dragging along a path in the central area of the applet -- the animation canvas. When you click on "Go!" all your currently defined animation objects will follow their trajectories at the same time. In order to erase anything in the drawings, this applet requires that you reload it (not very nice, I know!). However, you can create a new trajectory for any object by just redrawing it.
Four general options:
In response to your questions and in order to provide some additional flexibility in this assignment, the following four options are being presented. The one described above is the "Team of 2 people working from scratch" option.
|Individual working alone||Team of 2 people|
|working from scratch||core||core + 2 extensions|
|using code from ST (links below)||3 extensions:
2 from the list +
1 of your own
4 from the list +
2 of your own
The code for the sample solution is available in three files:
You are free to examine this code whether or not you choose to use it. If you use any of it, indicate that fact both in heading comments and in comments that appear with the excerpted code.