Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Need help understanding instructions for project.

 
Mack Grill
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm creating an Applet that will display 3 houses but I am a little confused on how to the instructions want me to create this

instructions:

"write an Applet class named Construction.java. It should build 3 houses (rectangles with triangle roofs on top) but its paint method should be only 3 calls to a method named drawHouse.

In Construction.java, you should (at least) define methods named: paint (which invokes drawHouse), drawHouse (which invokes drawTriangle and probably methods from the Graphics class), and drawTriangle."

I'm confused on how to set up the paint() method to make only 3 calls to the drawHouse() method and also how to invoke drawTriangle() into drawHouse()

here is my code so far:


 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
> I'm confused on how to set up the paint() method to make only 3 calls to the drawHouse() method

you have to draw 3 houses, don't you?
"It should build 3 houses (rectangles with triangle roofs on top)"

> how to invoke drawTriangle() into drawHouse()

same way you invoke drawHouse() from paint()

basically, you pass to drawHouse()
1) paint's graphic object
2) the location of the house
3) the width and height of the house.

2 and 3 could be combined to pass a Rectangle
 
Darryl Burke
Bartender
Posts: 5125
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Don't ever call resize(...) or otherwise change the state of a Component in a painting method override.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic