Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Graphics Program - Making House

 
Muzamil Farooqui
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Write a graphics program that generates the picture of a house, i need help getting started. Can someone guide the basics like putting the shapes in center and adjusting them. Please
 
Kemal Sokolovic
Bartender
Posts: 825
5
Java Python Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Did you try anything so far?
Try with drawing some basic shapes on panel (triangle, square, ...) and then worry about putting it all together.
 
Muzamil Farooqui
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Kemal Sokolovic wrote:Did you try anything so far?
Try with drawing some basic shapes on panel (triangle, square, ...) and then worry about putting it all together.


yeh i tried this,

GRect rect = new GRect(100, 50, 125, 60);
rect.setFilled(true);
rect.setColor(Color.RED);
add(rect);

}
}


now i need to know how i can move the shapes around, make them in center, make them fill the whole screen .
 
Kemal Sokolovic
Bartender
Posts: 825
5
Java Python Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, what you are using is not standard Java library class so I can't provide help with that code.

Anyway, use paper to do calculations you need. Draw one rectangle and another one (smaller) inside it, placed at the center of the first one. It will be easy to deduce the position of the smaller one in terms of the big one. Use that conclusion to place rectangle in your code at proper position.

Edit: In addition I would direct you to read Forum Naming Policy.
 
Muzamil Farooqui
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can someone else help me out please.
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
in standard java you'd use class variables for your bounds
ie instead of
new GRect(100, 50, 125, 60);
you might have
new GRect(x, y, w, h);

and if you wanted to change the position or size you'd adjust
those variables and call repaint()

I don't know what the GRect class is, so you'll have to read the docs
to see if the above is possible.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic