Lab 9: Java Graphics

Getting Started

  1. Read background on graphics
  2. Snarf the labs/lab9 project in Eclipse
  3. Add awb.jar to your buildpath
  4. Open MyDrawing.java and run as applet without making any changes to the code just yet!

  5. View the MyDrawing applet using appletviewer. All you will see is a blank white canvas and two IntFields for entering x and y coordinates. These coordinates specify the position of your drawing on the canvas.

To Do

The following items must be implemented to get credit for lab completion.

  1. Initialize and add the two Buttons bDraw and bClear. The Buttons should be labeled "Draw" and "Clear", respectively, and perform the following actions:

  2. The Draw subroutine is declared as follows:

    public void Draw (int x, int y)

    The subroutine takes as input two ints which represent the x and y coordinates of the drawing position on the canvas.

    You may draw whatever you want, as long as it "makes sense". For example, you can draw something simple such as the flower in the example below or create a pattern of geometric shapes, but you shouldn't just put a jumble of random shapes on the canvas. You should use several different shapes (such as lines, ovals, rectangles, etc.) and colors. Make sure that when you design your drawing you use the generic x and y coordinates passed into the Draw subroutine. The Java Graphics API contains method specifications for drawing shapes. It may be easier to add shapes one at a time, compiling and testing your applet in-between, or to sketch your shapes and coordinates on paper first.

    REMEMBER: The coordinate system for Java graphics starts at the upper left corner, and goes to the right and down!

Example

Below is an example of a possible implementation of the MyDrawing applet. When the Draw button is clicked the picture is drawn at the default coordinates (0,0), the canvas appears as follows:

If the coordinates (100,100) are entered and the Draw button is clicked, a second copy of the picture is drawn:



Receiving Credit

Full credit will be awarded for exceeding the minimum requirements - for example, creating a particularly elaborate and/or intricate drawing, or implemeting one of the suggestions below.


NOTE: If you decide to do extra credit work, add a short description of what you did in the space indicated (by "Extra work:") in the MyDrawing.html file.

The example below shows what happens when you click the "Tile" Button:


You are encouraged to think up and implement your own ideas as well.

Extra Extra Credit

Implement a recursive graphical structure like

Sierpinski triangles:

or H-Trees:

Submitting

Submit your MyDrawing.java and MyDrawing.html files using assignment name lab9 with Eclipse.

Did you put your name on your files?



Comments?
Last modified: Sun Oct 29 13:02:04 EST 2006