animated house. import java.awt.Color; import java.awt.Font; import java.awt.Graphics; import java.awt.Graphics2D; /** * * @author * */ public class MyHouse { public static void main(String[] args) { DrawingPanel panel = new DrawingPanel(750, 500); panel.setBackground (new Color(65,105,225));
Modify this code to make a moving animated house.
import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Graphics2D;
/**
*
* @author
*
*/
public class MyHouse {
public static void main(String[] args) {
DrawingPanel panel = new DrawingPanel(750, 500);
panel.setBackground (new Color(65,105,225));
Graphics g = panel.getGraphics();
background(g);
house (g);
houseRoof (g);
lawnRoof (g);
windows (g);
windowsframes (g);
chimney(g);
}
/**
*
* @param g
*/
static public void background(Graphics g)
{
g.setColor (new Color (225,225,225));//clouds
g.fillOval (14,37,170,55);
g.fillOval (21,21,160,50);
g.fillOval (351,51,170,55);
g.fillOval (356,36,160,50);
}
static public void house (Graphics g)
{
g.setColor (new Color(139,69,19)); //house
g.fillRect (100,250,400,200);
g.fillRect (499,320,200,130);
g.setColor(new Color(190,190,190)); //chimney and doors
g.fillRect (160,150,60,90);
g.fillRect (245,380,110,70);
g.fillRect (508,350,180,100);
g.setColor (new Color(186,134,11)); //door handle
g.fillOval (282,412,10,10);
g.fillOval (307,412,10,10);
}
static public void houseRoof (Graphics g)
{
g.setColor(new Color(190,190,190)); //house roof
int x[] = {98,300,501};
int y[] = {250,130,250};
g.fillPolygon(x,y,3);
}
static public void lawnRoof (Graphics g)
{
g.setColor (new Color(190,190,190)); //lawn roof
int x[] = {499,499,700};
int y[] = {320,249,320};
g.fillPolygon(x,y,3);
}
static public void windows (Graphics g)
{ g.setColor (Color.orange); //windows outer frame effect
g.fillOval (521,350,68,31);
g.fillOval (606,350,68,31);
g.fillRect (121,261,78,78);
g.fillRect (401,261,78,78);
g.setColor (Color.white); //windows with frames
g.fillRect (125,265,70,70);
g.fillRect (405,265,70,70);
}
static public void windowsframes (Graphics g)
{
g.setColor (new Color(139,69,19)); // door sections
g.fillRect (299,380,2,70);
g.fillRect (507,382,180,2);
g.fillRect (507,417,180,2);
g.setColor (new Color(186,134,11)); //inner frame effect
g.fillRect (156,265,5,70);
g.fillRect (436,265,5,70);
g.fillRect (124,298,70,5);
g.fillRect (404,298,70,5);
g.fillRect (244,375,110,5); //door frame
g.fillRect (241,375,5,75);
g.fillRect (354,375,5,75);
g.fillRect (508,345,180,5);
g.fillRect (505,345,5,105);
g.fillRect (684,345,5,105);
}
static public void chimney (Graphics g)
{
g.setColor (new Color(210,180,140)); //smoke for chimney
g.fillOval (162,106,36,44);
g.fillOval (172,96,36,44);
g.fillOval (162,86,36,44);
g.fillOval (172,36,36,44);
g.fillOval (162,26,36,44);
g.fillOval (172,16,36,44);
}
Trending now
This is a popular solution!
Step by step
Solved in 2 steps