Homework 1: Drawing
Assigned: September 4, 2001
Due: September 18, 2001
(See references on using Java Swing and Java 2D)
imageloader.java that might help with
homework 1
Create a Java Swing program that illustrates how Java 2D (the Graphics2D
object) and Java AWT graphics (the Graphics object) handle at least the
following issues. For some operations, they will not be possible in the older
AWT graphics system, so just answer those questions using Java 2D.
Note: you do not necessarily need different pictures for every
question. If you can figure out a way to have one picture clearly answer
multiple questions, that is fine, just be sure it is labeled.
Note: the labels for the answers to questions can just be numbers which
are then referenced in your hardcopy description. But the labels should be part
of the picture generated by the code you write (rather than hand-written on
the hardcopy output or screen capture). It is OK if the labels are label objects
inserted with your Interface Builder.
You should create a program that creates a large window (but less than
1024x768) that illustrates and answers the following questions. Your window
should end up containing drawn graphics on all the various kinds, with labels
(text strings) that show the answers to these questions and how you measured the
answers. Probably, all your code will be put into the public void paint (Graphics g){
} method of your class with extends javax.swing.JFrame. If all of
your graphics doesn't fit into one window, you might have one JFrame for AWT and
another for Java2D, or if that is too hard, you might have two different
programs, one for AWT and one for Java2D.
You should turn in:
- A hardcopy report containing:
- a printout of your screen (e.g., using the PrintScreen
keyboard key).
- The written answers to the following questions. Note: you might want to
just copy this file and fill in the answers so you don't have to retype the
questions.
- You should email me (bam@cs.cmu.edu)
with a .zip file containing your program source, executable and report in a format I
can deal with.
- Your email message must have the Subject: "631 HW1 " and
then your name.
- The name of the .zip file must include your name.
- The .zip file should include a README.txt file explaining how the program
should be compiled and how it should be run (e.g., in
CodeWarrior, or from the DOS command line, etc.). I strongly
prefer to test your interfaces using Windows. Note: do not include
this information in the body of your email message. The body of the message
should be empty: put the instructions in the README.txt file in your .zip
file.
- The zip file should also include an electronic version of your hardcopy
report.
- Grading: Your program will be compiled and run on my machine. If your program
performs properly, is well structured, and is copiously documented you will receive
93 out of 100 points (a low A). To receive additional points you need to do something "extra" of your own design which
answers additional questions besides those listed below that are of the same
kind. Please describe any "extra" questions you have included in your
hardcopy printout. Extra points will depend on how interesting and
informative the questions and answers are. The tentative detailed grading breakdown for this assignment is as follows: Turned in and compiles:
25 points; No crashes: 10 points; Good commenting: 5 points.
Answers all the questions correctly: 53 points; extra questions: 7 points.
- Late Policy: Homeworks are due at 5pm on September 18, 2001. Late
penalty: 5 points per day (out of 100) for each day late (including
weekends).
The questions for Homework 1:
- Background: Which specific versions of Java, Swing, Java2D, and compilers
are you using, and on what platform? What specific Window system are you
using (and which window manager, if under Unix)?
- Where is the coordinate 0,0 with respect to the window borders by default? In
particular, is it at the top-left, bottom-left, etc? Is it just inside or
just outside the drawable part of the window? Can the coordinate system be changed?
- When you draw the outline of an object like a rectangle or line and
specify a position and size:
- What exact pixel does the drawing start on?
- Is the "other end" of the object defined using a WIDTH-HEIGHT,
or a SECOND-POINT? Is this consistent for all shapes (rectangles, lines,
ovals, polygons, etc.)? Is the "other end" inclusive or exclusive
(does the "other end" point get drawn)? If rect1 is size W, where
would rect2 start if they should not overlap?
- How do the answers change if you specify a line width that is more than
one?
- For line widths > 1, which way does the extra width go (inside, both
sides, etc.)? For example, drawing a rectangle with line width LW where the
upper left position of the rectangle is specified as position P, where is
the first pixel drawn? (It may be less than P.) Be sure your answer is accurate
both for when P is even and odd. Is the answer different for rectangles,
ovals and for lines?
- When you draw a filled object, like a rectangle or oval, and
specify a position and size:
- What exact pixel does the drawing start on? Is it the same as for drawing
an outline object?
- What exact pixel does the drawing end on? Is the size inclusive or
exclusive? If rect1 is size W, where would rect2 start if they should not
overlap?
- If you want to draw an object that is both filled and has an
outline, can you use the same coordinates for both?
- For an object that is both filled and has an outline, if the outline has
a line-width > 1, are there gaps between the outline and the
filled portion for polygons, ovals, etc.?
- What fill styles are supported? (Solid, patterns, gradients?) Show
examples (label which is which!).
- For polylines, how do you make the polygon be open or closed? Is the last
one point drawn twice?
- Are Solid, dashed, "double-dashed", and patterned lines supported? Show
examples (label which is which!).
- What cap-styles are available for lines? Show examples (label which is
which!).
- Are
Mitered, Rounded and Beveled ends supported for polylines? Show examples
(label which is which!).
- What rule is used to fill self-overlapping polygons (like the 5-pointed
star)? Can the programmer pick?
-
Can drawing operations and CopyArea be performed using various
DrawFunctions, like XOR and AND? If so, show examples of why XOR and AND don't work well in color.
(E.g., show black
and white graphics XORed over colored graphics).
- If you set your monitor to 256 colors, and select a color that is
not in your color table, then what is done? (It crashes? Picks a
"close" color? Halftoning?)
- Is "alpha blending" supported? Show examples.
- Are multiple fonts for text supported? How is the desired font specified?
- Can text be rotated? Show examples.
- Text and font spacing information (show examples to illustrate answers):
- When you ask for the width of a string or character, does it include
spacing information?
- When you ask for the height of a string or character, does it include
spacing information?
- Do you need to add or subtract extra space (vertically or horizontally) if you want
to draw a box tightly around a string?
- Do you need to add or subtract extra space (vertically or horizontally) if you want
to draw another string at the appropriate place next to a string?
- Draw a few strings with significantly different font styles and sizes to
show you know how to find out and align the baselines.
- Draw 2 or 3 examples of images (pictures) from .gif, .jpeg or other format
source picture files.
- Clipping (show examples to illustrate answers)
- Is clipping the drawing to a rectangle supported?
- What about clipping to multiple
rectangles?
- If so, can you specify a clipping region where the specified
clipping rectangles are overlapping?
- If so, can you specify a clipping region where the specified
clipping rectangles are disjoint (not touching)?
- Can you clip to arbitrary shaped regions?