Homework 1: Drawing

05-631: Software Architecture for User Interfaces, Fall, 2001

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:

The questions for Homework 1: 

  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)?
  2. 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?
  3. When you draw the outline of an object like a rectangle or line and specify a position and size:
    1. What exact pixel does the drawing start on?
    2. 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?
    3. How do the answers change if you specify a line width that is more than one?
    4. 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?
  4. When you draw a filled object, like a rectangle or oval, and specify a position and size:
    1. What exact pixel does the drawing start on? Is it the same as for drawing an outline object?
    2. 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?
    3. If you want to draw an object that is both filled and has an outline, can you use the same coordinates for both?
    4. 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.?
  5. What fill styles are supported? (Solid, patterns, gradients?) Show examples (label which is which!).
  6. For polylines, how do you make the polygon be open or closed? Is the last one point drawn twice? 
  7. Are Solid, dashed, "double-dashed", and patterned lines supported? Show examples (label which is which!).
  8. What cap-styles are available for lines? Show examples (label which is which!).
  9. Are Mitered, Rounded and Beveled ends supported for polylines? Show examples (label which is which!).
  10. What rule is used to fill self-overlapping polygons (like the 5-pointed star)? Can the programmer pick?
  11. 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).
  12.  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?)
  13. Is "alpha blending" supported? Show examples.
  14. Are multiple fonts for text supported? How is the desired font specified?
  15. Can text be rotated? Show examples.
  16. Text and font spacing information (show examples to illustrate answers):
    1. When you ask for the width of a string or character, does it include spacing information?
    2. When you ask for the height of a string or character, does it include spacing information?
    3. Do you need to add or subtract extra space (vertically or horizontally) if you want to draw a box tightly around a string?
    4. 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?
    5. Draw a few strings with significantly different font styles and sizes to show you know how to find out and align the baselines.
  17. Draw 2 or 3 examples of images (pictures) from .gif, .jpeg or other format source picture files.
  18. Clipping (show examples to illustrate answers)
    1. Is clipping the drawing to a rectangle supported?
    2. What about clipping to multiple rectangles?
    3. If so, can you specify a clipping region where the specified clipping rectangles are overlapping?
    4. If so, can you specify a clipping region where the specified clipping rectangles are disjoint (not touching)?
    5. Can you clip to arbitrary shaped regions?