All you have to do is copy the information to the blanks.
Here is the applet with all the blanks filled in. With skillful use of the text editor, much of this filling in is easily done using "copy" and "paste".
import javax.swing.JApplet; import java.awt.*; // assume that the drawing area is 350 by 250 public class HouseRectangles extends JApplet { final int width = 350, height = 250; final int houseX = 65, houseY = 100, houseW = 110, houseH = 110 ; final int doorX = 120, doorY = 165, doorW = 25, doorH = 40 ; final int lWindX = 90, lWindY = 115, lWindW = 30, lWindH = 30 ; final int rWindX = 130, rWindY = 115, rWindW = 30, rWindH = 30 ; final int trunkX = 255, trunkY = 100, trunkW = 10, trunkH = 100 ; public void paint ( Graphics gr ) { gr.setColor( Color.orange ); // there is no Color brown gr.drawRect( houseX , houseY , houseW, houseH); // house gr.drawRect( doorX , doorY , doorW , doorH ); // door gr.drawRect( lWindX , lWindY , lWindW, lWindH); // lwind gr.drawRect( rWindX , rWindY , rWindW, rWindH); // rwind gr.fillRect( trunkX , trunkY , trunkW, trunkH); // trunk } }
Here is the beautiful picture that it produces:
The tree trunk is a solid rectangle because the fillRect()
method
was used.
This method is just like drawRect()
except that it fills the figure with the current color.
The door is not really where we want it. We could go back to the graph paper and carefully read off its coordinates, or calculate its coordinates from those of the house.
You want the door horizontally centered.
houseX
, and houseW
what is the X value of the center of the house?doorW
,
what is the X value of the left edge of the door, doorX
?