CSCI 201 Lab 6 -- Making Faces with Java

In this lab, you'll write a java applet that draws a face.

Getting ready

Let's start by reviewing some of the things that we learned about applets in Lab 4:

  1. An applet must be "called" from an HTML document. In jGRASP you must also modify the default HTML code.
  2. Applets do not have a main method, their execution is controlled by the web browser.
  3. All applets are created by extending the applet class or, in Java swing, the JApplet class.
  4. When we write an applet, we need to define a method called paint that is responsible for creating the applet display.
  5. The paint method always has a single parameter, a Graphics object.

If any of these concepts are fuzzy take a second look at Lab 4 or review the relevent sections of your textbook.

Starting Your Applet

We're going to give you a jar file containing a Java applet, an HTML file, and a jGRASP project to start this lab. Go ahead and download the lab jar file and then start up jGRASP and extract the files of the jar into the directory C:\Files\Lab06, on Windows, or csci/201/Lab06, on Linux. There's always Lab 2 if you can't remember how to do this.

Go ahead and open the project file Face.grp and then open up and Face.html into their own CSD windows. Now compile and then make the HTML code of Face.html be the HTML contents for "Run as Applet". This last step is rather tricky. You may want to review the section Setting the "default" HTML of Lab 4 for help.

Run the program and look at the display created by the applet. You should see a rather abstract face with only a nose and mouth. If the entire face is not painted, move your mouse into the appletviewer window.

Enhancing Your Face

You need to modify the paint method of Face to produce an improved face. (Ah, if all of live were so easy.) You are expected to be creative, both in designing the face and in using Java classes. Look at Sun's documentation for the Color and Graphics classes to see what colors and graphic objects are available. You might also find your textbook to be useful.

Understanding the Documentation

Take a look at Sun's on-line documentation for the fillArc method of Graphics. Everything we needed to know to draw that nose is located in this information. You just have to read and understand it. So give it a try! (By the way, reading and understanding documentation is a major part of the work life of a computer professional.)

In order to use the Graphics methods, you need to remember how the display coordinate system is setup. The origin of the coordinate system is the top-left corner of the display, with the positive x-axis running horizontally to the right, and the positive y-axis running vertically down (not up) the right side of the display. Also, distances are measured in terms of pixels, the little dots that make up your screen.

Also, the order in which the objects are drawn to the screen makes a difference. If you want to draw a black pupil in the center of a green iris, you must draw the surrounding iris first.

Lab Checkoff

This lab has more indefinite goals than the previous ones. However, it has few definite rules:

  1. You are strongly encouraged to work with a partner.
  2. You must use at least one color not seen in the original code.
  3. You must use at least two additional methods of Graphics. We suggest you choose fillOval for one of your two.
  4. You can not leave for at least one hour.
  5. Your Java-generated face must not resemble that of your lab instructor.

Some examples from the past

Here are some of the faces that students have created in the past when CSCI 201 was taught using C++. Most of these folks actually graduating from UNCA in spite of this assignment.