Graphic by Keith Ohlfs |
|
In lecture you have seen how to create and use methods to draw a pattern of different sizes and positions without having to write the same lines of code repeatedly. In lab 4, you will be using methods to build a castle. In this prelab, you will create a method for one component of this castle: an arch.
1) First, download the folder, castle, from the download directory for cs111 on Nike. This folder contains 4 files:
3) Open the project window and double click on castle.java to look at the source code. You will see only one method, the paint method, that contains all the drawing statements. Your goal is to create a new method, called "drawArch", that takes seven parameters and draws an arch. The parameters are those listed at the top of paint and are as follows:
4) Modify the java source file as follows:
this.drawArch(g, Color.red, Color.blue, 50, 150, 100, 75);
public void drawArch(Graphics g, Color archClr, Color gateClr, int x, int y, int width, int height)
{
The code to draw the arch goes here.
}
5) Once you have created the drawArch method, use it to create three arches side by side. (You will need three statements in your paint method, which call drawArch with different parameters). Use the following parameters:
  | Arch Color | Gate Color | x | y | width | height |
Arch 1 | Blue | Red | 50 | 200 | 100 | 75 |
Arch 2 | Green | Yellow | 150 | 200 | 75 | 75 |
Arch 1 | Red | Blue | 225 | 200 | 100 | 150 |
When you view your applet, it should look like this:
When you are finished. Save the four new castle files (castle.java, castle.proj, castle.class and castle.html) in a folder named "username_prelab4", where username is your username. Upload this folder into the lab4 drop folder on Nike.