Results 1 to 3 of 3
  1. #1
    alecia27 is offline Member
    Join Date
    Sep 2012
    Posts
    1
    Rep Power
    0

    Default How can i make mutiple house appear on my screen and populate it off this program

    I need to supply a house constructor for specifying the position and size
    i'm new to programming so i don't really understand java as much


    import java.awt.Graphics;
    import java.awt.Graphics2D;
    import java.awt.Color;
    import java.awt.geom.Line2D;
    import java.awt.Rectangle;

    public class House {

    private int xLeft;
    private int yTop;
    private Color color;

    public House(int x, int y, Color color)
    {
    xLeft = x;
    yTop = y;
    this.color = color;
    }

    public void draw(Graphics2D g2)
    {
    Rectangle body
    = new Rectangle(xLeft, yTop + 40, 80, 80);
    Rectangle door
    = new Rectangle(xLeft + 10, yTop + 70, 30, 50);
    Rectangle window
    = new Rectangle(xLeft + 50, yTop + 80, 20, 20);
    Line2D.Double line1
    = new Line2D.Double(xLeft, yTop + 40, xLeft + 40, yTop);
    Line2D.Double line2
    = new Line2D.Double(xLeft + 40, yTop, xLeft +80, yTop + 40);

    g2.setColor(color);
    g2.draw(body);
    g2.draw(door);
    g2.draw(window);
    g2.draw(line1);
    g2.draw(line2);
    }
    }

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,556
    Rep Power
    25

    Default Re: How can i make mutiple house appear on my screen and populate it off this program

    Take a look at the tutorial about how to write constructors:
    Providing Constructors for Your Classes (The Java™ Tutorials > Learning the Java Language > Classes and Objects)


    Please edit your post and wrap the code in code tags. See: http://www.java-forums.org/misc.php?do=bbcode#code
    If you don't understand my response, don't ignore it, ask a question.

  3. #3
    DarrylBurke's Avatar
    DarrylBurke is online now Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,404
    Rep Power
    20

    Default Re: How can i make mutiple house appear on my screen and populate it off this program

    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

Similar Threads

  1. Replies: 9
    Last Post: 09-06-2012, 09:37 AM
  2. Replies: 6
    Last Post: 08-18-2012, 09:54 AM
  3. Replies: 15
    Last Post: 03-01-2012, 12:21 PM
  4. Replies: 1
    Last Post: 01-25-2010, 01:21 PM
  5. How to make an icon in bottom-right of screen
    By hunterbdb in forum AWT / Swing
    Replies: 1
    Last Post: 08-13-2009, 08:28 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •