In this lab, you'll write a java applet that draws a face.
Let's start by reviewing some of the things that we learned about applets in Lab 4:
main
method, their execution is
controlled by the web browser.
applet
class
or, in Java swing, the JApplet
class.
paint
that is responsible for
creating the applet display.
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.
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 Face.java and Face.html into their own CSD windows. Now compile Face.java 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.
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.
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.
This lab has more indefinite goals than the previous ones. However, it has few definite rules:
Graphics
. We suggest you choose fillOval
for one of your two.
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.