Homework #3:
Simple graphics programming
For this homework, you will create a Swing application
named 'SwingTest03'. The application will create a window and
draw a number of 2D shapes in various colors. The requirements
for the application are as follows:
-
The application must belong to a package named
cis370.hw03.
-
The window's height and width must be 3/4 of the
corresponding screen dimensions.
The window must be centered on the display.
-
Create and display
at least a dozen different 2D shapes of at least four
different kinds. You may choose any shape supported by the
Java2D library (RoundedRectangle, Ellipse, etc.)
-
Select the type of each shape, and its coordinates and dimensions,
randomly at runtime (so no two runs of the application will show
the same display).
-
The minimum size of each shape should be 10 pixels in either
direction; the maximum size should be 3/4 of the corresponding
window dimension.
-
Object locations should be chosen so that some objects may be
only partially displayed. However, every object should be at least
partially visible.
-
Use methods of the Random class to generate
int and double random numbers as necessary.
(Hint: You should use just one Random object to generate
every
random number in your application.)
-
Generate the colors of the shapes randomly.
-
As usual, your source files should include well-formed and
informative javadoc comments.
-
IMPORTANT:
Your program must handle screen redraws correctly—if the display
window is obscured or minimized, then brought back to the front,
all shapes should still be visible and unchanged.
-
Extra credit:
Label each object in a monospaced 12-point font, in a color which
contrasts with the object's randomly-generated color.
Center the label on the object.
(It's OK if the label is wider than the object,
or is cut off by the edge of the window.)
The labels should be "type 0",
"type 1", and so forth, where
type is the shape's class name
("Rectangle", "Circle", etc.)
and the number reflects the order in which the objects were generated.
Due date:
The homework is due at the beginning of class on 30 September.
Turn in:
(1) A listing of the source file(s) for the application.
(2) Screen dumps of at least two runs of your application (color
output is not necessary).
E-mail:
A Zip or tar archive file containing all of your source files
(including package.html)
to grading@bozoid.com.
The subject of the e-mail should be "SwingTest03", and the
archive name should be hw03.zip or hw03.tar.gz.
In addition to your source files, the archive file should include
a text file named readme.txt containing your name and
any other identifying information you think is appropriate.
Do not include .class files, javadoc files,
or screen dumps in the e-mail.
Note: Staple all the pages of your submission
together, and make sure you put your name on your homework!