CSCI 201 Spring 2003
Programming Project 2
In
lab you learned how to write an Applet---a java program that runs
in a browser window. As your second programming project, you will
work problem 3.25 in your text in which you will write an Applet.
Problem 3.25 tells you to create a quilt of your own design, but we
are going to be more specific. Here are the steps that you should
follow in writing this program:
- Begin with the Bullseye program (example 3.18) from your text.
You can get that program from this link or
from the homepage for
your text. You will also need the accompanying HTML document. (Download these files by
right-clicking on each link and selecting Save Target As
from the pop-up menu.)
- Open Bullseye.java in Netbeans and set the file executor property
to "Applet Execution" ((Help).
- Compile and execute Bullseye.java and make sure that you
understand the output and how it is generated.
- Modify Bullseye.java and Bullseye.html as follows:
- Change Bullseye.java to Quilt.java, both the class name
and the file name. Rename Bullseye.html to Quilt.html and change all
references to Bullseye inside of Bullseye.html to be references to
Quilt.
- Modify the paint() method in Quilt so that it produces
one patch of your quilt. That patch should consist of three
concentric squares with each square being a different color of your
choice (see page 114 of your text for more information on the Color
class). The "patch" (i.e., the three concentric squares) should fill
1/3 of the width and height of your display, as shown below. This can
be accomplished by changing the size of the squares in Quilt.java
and/or the size of the display specified in Quilt.html.
- Now, create 2 copies of the paint() method in your
Quilt class and modify the second copy of paint() as follows:
- Replace the header of the method:
public void paint (Graphics page)
with
public void drawPatch(Graphics page, int xInitial, int yInitial)
- Modify the code in the method that is now named
drawPatch() to produce a patch of your quilt such that the upper-left
corner of that patch is at the coordinates xInitial, yInitial. In
other words, every time the method drawPatch() is called it draws a
patch at position xInitial, yInitial. Be sure to remove any code that
does not pertain to drawing a single patch from the drawPatch method.
- Now, remove the code pertaining to drawing a patch from
the paint() method and replace it with a call to your new drawPatch()
method. Make sure that this works before proceeding.
- Now you are ready to draw your entire quilt. Start by
modifying your program to produce the first row of squares in your
quilt. (Note: all modifications should take place in paint().) Each
row should consist of 3 patches as shown below. You must use a
looping structure to receive credit for this portion of the
assignment. (Hint: Even though the size of the patch may be stored in
MAX_WIDTH located in the drawPatch() method, you need to know and use
the patch size in the paint() method. In the future, we will discuss
a better way to design this program, but for now just look at the
numeric value of MAX_WIDTH and used that number in paint().)
- Complete your quilt by modifying your program to
produce 3 rows of patches as shown below. Again, you must use a
looping structure to receive credit for this portion of the
assignment. You are done!
Programming Style
Note that 10% of your program grade is based on the readability of
your program. This includes things like proper indentation, comments,
and the naming of variables and methods as described in the style
guide for this class. To receive full credit for your program,
make sure that you use proper indentation as demonstrated in your text
and in class room examples. Also include comments at the top of each
program stating your name, the course, and the purpose of the program:
For example:
/*
** Name: your name here
**
** Course: CSCI 201
**
** Purpose: purpose of program here
*/
Submitting Your Program
The program written for this assignment must be turned in by
transferring the java source code file and the HTML file to your ftp
directory for this class. Both the source code file (i.e.,
Quilt.java) and the HTML file (Quilt.html) should be turned in and the
files must have exactly those names.
You were shown how
to transfer files to your class ftp directory in lab
1.