CSSE 220: Object-Oriented Software Development
Faces

You will do this exercise by yourself, but be quick to ask questions of your instructor, student assistants and classmates as desired.

Goals

This exercise will let you:

Grading rubric

Total possible: 50 points.

Do this project using documented stubs throughout.

Use good style throughout.

For any points deducted, the grader will put a CONSIDER tag saying how many points were deducted and why.

“Earn back” may be available for this assignment; ask your instructor.

Here is a link to the General Instructions for Grading Programs.

Overview

You will implement this project in stages, testing at each stage to see if the project works correctly through that stage.

Before beginning work, read over the titles of the seven stages below. Those titles are the iterative enhancement plan for this program and will give you a sense of what you're up against. You should also look at the figures in each stage.

Once you have an idea of what’s expected, begin working at Stage 0 and proceed through the stages in order, getting help as needed.

Don't forget to commit your changes to SVN after each stage!

Implement the project

Implement according to the following Iterative Enhancement Plan (IEP):

Stage 0. Read the specification, then design the project using a UML class diagram

Here is a specification of this project:

Here is the UML class diagram for Faces that we developed together in class. 

 

Stage 1. An empty 500 x 400 frame appears

Stage 1: Frame appears
  1. Open Eclipse.
  2. From your individual repository, checkout the Java project called Faces

  3. Create a new class called FacesViewer with the usual main method.

  4. Write documented stubs for FacesViewer and its main method.

  5. Implement and test your documented stubs.

  6. Commit your work.

Stage 2. A circle and a filled circle appear (drawn onto a JComponent that is added to the JFrame)

Stage 2: A circle and a filled circle appear on the frame

Recall that you don't normally draw directly onto a JFrame. Instead, you:

Proceed as follows:

  1. Create a class called FacesComponent that extends JComponent.
  2. Override the paintComponent(Graphics) method that FacesComponent inherits from JComponent.
  3. Write documented stubs for FacesComponent and its paintComponent method.
  4. Implement FacesViewer and FacesComponent per this stage and test your documented stubs.

  5. Refer to Stage 2 of the SwingDemo1 instructions (for instructions on drawing in general) and Stage 4 of the SwingDemo1 instructions (for instructions on drawing circles) if you need reminders for how to accomplish this stage.
  6. After you are convinced that FacesViewer and FacesComponent are working correctly for this stage, comment-out the tests that make a circle and a filled circle appear.

Stage 3. Filled Faces appear, but with no outline and no eyes and mouth yet

Stage 3: Faces with no eyes and mouths appear on the frame
  1. Create a Face class.
  2. Write documented stubs for Face, including (at this point) its:

    Also modify your documented stub for FacesComponent to indicate that it (at this stage)

    Displays filled faces, but with no outline and no eyes and mouth yet

    since that is all that FacesComponent should do at this stage.

  3. Implement Face and FacesComponent per this stage and test your documented stubs.

Stage 4. Filled Faces appear, with outlines and eyes, but no mouth yet

Stage 3: Faces with outlines and eyes but no mouths appear on the frame
  1. Augment/modify your documented stubs for Face to include (at this point):

    Modify your documented stub for FacesComponent to indicate that it (at this stage)

    Displays filled faces with outlines and eyes, but no mouth yet

    since that is all that FacesComponent should do at this stage.

    Also augment your documented stub for Face's drawCircle method to indicate that it has a parameter that determines whether to draw the circle filled or not.

  2. Implement Face and MyComponent per this stage and test your documented stubs.

Stage 5. Filled Faces appear with outlines, eyes and mouths

Stage 3: Faces with outlines, eyes and mouths appear on the frame
  1. Augment your program to draw the mouths of your Faces, as in the picture.

Stage 6. Faces can be rotated and be translated

Stage 6: Translated and rotated faces appear
  1. Implement a translate(double x, double y) method that translates the Face's position by the amounts given in the arguments. (See the specification in Stage 0 for code you can copy to create the documented stub.)

  2. Implement a rotate(double angleToRotate) method that rotates the Face by the number of degrees given in the argument. (See the specification in Stage 0 for code you can copy to create the documented stub.)

Stage 7 (optional). Run as an applet, then turn in your work

An Applet is Java code that can be run from a browser. As you will see, it is VERY easy to make an Application (which you have written) into an Applet.

  1. Examine the FacesApplet code that we supplied. Note that it is trivial to make an Application into an Applet — just a few lines of boilerplate per the example that we supplied, plus a call to the JComponent class that your Application adds to a JFrame.

  2. Select the FacesApplet class and press the Run button in Eclipse. (Or right-click on FacesApplet and select Run As ... Java Applet.) You should see your project run in the built-in Applet Viewer. It will look almost identical to the Application (just the title changes).
  3. Outside of Eclipse, find the Faces.htm file in your bin subfolder of your Faces project.

    Open the Faces.htm file in your bin subfolder (that is, double-click on the file), to bring it up in a browser. It should look very similar to what you just saw in the Applet Viewer.

  4. Examine the html code in the Faces.htm file (by opening it in WordPad, for example). Note that it is very simple to embed an applet in an html file.

Turn-In Instructions

Commit your project to your individual repository when you are done.