Program 2: ShapeDrawer
- Assigned On: 10/24/2005
- Due On: 11/02/2005
Write a java applet that reads a text file containing shape information and draws the appropriate shapes to the screen.
There are four kinds of objects in the shape file; solid rectangles, solid ovals, solid arcs and lines. Each line in the input file
describes a single shape.
A square is a special case of a rectangle where the width and height are equal. A circle
is a special case of an oval where the width and height of the bounding box are equal.
Each line of the input file begins with the kind of shape it describes and then
contains the parameter list for that shape. All numerical parameters will be integers.
Your program should support 13 colors: black, blue, cyan, darkGray, gray, green,
lightGray, magenta, orange, pink, red, white, and yellow. These colors are
static members of the class Color (see page 1008).
Here are some example input files:
Here are the exceptional student-submitted drawings.
Because you will be reading from a file, you will have to handle
FileNotFoundExceptions. Working within the confines of the applet, you're
restricted in how you may declare exception throwing. (That is you may not
redefine the signature for "public void paint( Graphics g)" to also "throw
FileNotFoundException"s). I am providing the following code block that you may
public void paint( Graphics g )
readInputFile( g );
catch (FileNotFoundException fnf )
public void readInputFile( Graphics g ) throws FileNotFoundException
//The rest of this method and any other methods you wish to define
//are left to you
Because reading from files is tricky with Applets, you will run your program
locally (on your computer) instead of imbedding it within a webpage. If you try
to imbed your program in a webpage, you will encounter a security
exception. There are ways to get an applet to read from a file located at some
URL, but they are involved.
Type the honor pledge at the top of your .java file in a comment block.
Zip 1) your .java file and 2) your .class file 3) a screen shot of an original
drawing and 4) the text file holding your original drawing into a single file.
Name that file <your onion>_pr02.zip. That's the name it should have on
your computer. Use blackboard to SEND
your .zip file.