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);
}
}
Re: How can i make mutiple house appear on my screen and populate it off this program
Re: How can i make mutiple house appear on my screen and populate it off this program