CS 201 - Computer Science I - Spring 2009
Lab 7 - Graphics and Selection
Loyola College >
Department of Computer Science >
Dr. James Glenn >
CS 201 >
Labs >
Lab 7
Due
Monday, March 16th at 11:59pm.
Labs submitted one day late will be assessed a
20% penalty. Labs will not be accepted more than one day late.
Objectives
- to use methods from the Graphics class
- to use selection statements
Reading
Anderson and Franceschi, Chapters 4 and 5
Assignment
Add code at the specified location in
AnimatedAppletL7.java that draws
a simple picture. Your picture should use
- shapes of at least three different types (rectangles, ovals, etc.),
- text,
- several different colors including one custom-mixed color, and
- layering (shapes drawn on top of other shapes).
You should also strive to have your drawing scale to fit the size of
the applet.
In addition, you should use selection (if and if/else)
statements to satisfy the following:
- one of your objects should be drawn only during certain frames
of the animation; and
- another should be drawn one way during some frames
and a different way during other frames (the difference can be in color,
position, size, etc.).
To determine when to draw what, you will need
to use conditions that involve the frame variable that is set up
at the beginning of paint in the provided code. The frame
variable keeps track of how far the animation is into a 10 second cycle,
counting by fifths of a second. The values for frame will therefore
be between 0 and 49 (inclusive) and so if you want something visible only
half of the time, you could write a selection statement with a condition
that expresses "frame is between 0 and 25".
For complete information on the methods to use from the
Graphics class, see the
documentation.
Suggestions
Make a sketch of your drawing on paper and try to figure out what all the
coordinates will be before writing the code.
Extra Credit
- Use a Polygon object to draw shapes that are more complex
than ovals, rectangles, etc.
- Use a Font object and setFont to display your
text in a non-default font.
Submissions
Submit the source code (.java file) for your AnimatedAppletL7 class.