Lec 18 Writing Methods that Draw Graphics

advertisement
Lec 18
Writing Methods that Draw Graphics
Agenda
• More Applet stuff
– Methods that draw things on screen
• (house, car, tree, etc)
• use of "this" again
– Higher level groupings (block, neighborhood)
Methods as Building blocks
• Want to draw more complex pictures?
– a scene of houses and cars, or a farm scene
• Make a method called drawHouse
– like a stamp we can use to make many copies
– we just say what to draw and where to draw it
Methods can call other methods
• Suppose you want a row of houses (a block)
• drawBlock method can invoke house method
public void drawBlock(Graphics g, int x, int y){
int k=0;
while (k<6){
this.drawHouse(g, x + k*60, y);
this.drawTree(g, x+k*60+50, y);
k++;
}
}
Lab18BarnyardApplet
• Make a drawCow method, a drawBarn
method, drawDuck, drawPig, etc and plant
many copies all over yard.
Download
Related flashcards
Writing

19 Cards

Stationery

14 Cards

Cyrillic letters

38 Cards

Letters (message)

33 Cards

Create flashcards