Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write an applet that draws the house shown in the book on page 933. I have inclu

ID: 3621788 • Letter: W

Question

Write an applet that draws the house shown in the book on page 933. I have included coordinates for the house. Please make improvements if you wish. The program should make the house look like black squares or rectangles for the windows and doors. When the user clicks on them they should open (become white with black outlines for the door, door knob, windows and window panes. I dont like my program and really need to see something great. Adding audio clips would be awesome for the door opening and windows closing. I cant quite figure that out.

import java.awt.*;
import java.applet.*;
import java.awt.event.*;

public class HouseTestB extends Applet
{
boolean winleft, winright, roof, base, door;
public void init()
{
winleft = winright = roof = base = door = false;
setBackground(Color.WHITE);
addMouseListener(new MyMouseListener());
}

public void paint(Graphics g)
{

super.paint(g);
// roof

if (roof)
{
g.fillPolygon(new int[] {156,0,299}, new int[] {99,150,150}, 3);
}

if (winleft)
{
g.fillRect(50, 155, 50, 70);
}

if (winright)
{
g.fillRect(200, 155, 50, 70);
}

if (door)
{
g.fillRect(120, 155, 50, 100);
}

// window left
g.drawLine(156, 99, 0, 150);
g.drawLine(156, 99, 299, 150);
g.drawLine(0, 150, 299, 150);


// base
g.drawRect(3, 150, 296, 110);


g.drawRect(50, 155, 50, 70);
g.drawLine(50, 185, 100, 185);
g.drawLine(75, 155, 75, 225);

// door
g.drawRect(120, 155, 50, 100);
g.fillOval(158, 200, 5, 10);

// window right
g.drawRect(200, 155, 50, 70);
g.drawLine(200, 185, 250, 185);
g.drawLine(225, 155, 225, 225);

}

private class MyMouseListener implements MouseListener
{
public void mousePressed(MouseEvent e)
{
}

public void mouseClicked(MouseEvent e)
{
int currentx = e.getX();
int currenty = e.getY();

boolean WindowLeft = (currentx >= 50 && currentx < 77 && currenty >= 155 && currenty <= 225);
if (WindowLeft)
{
winleft = true;
repaint();
}

boolean Roof = (currentx >= 0 && currentx < 299 && currenty >= 99 && currenty <= 150);
if (Roof)
{
roof = true;
repaint();
}

boolean Door = (currentx >= 120 && currentx < 170 && currenty >= 155 && currenty <= 255);
if (Door)
{
door = true;
repaint();
}

boolean WindowRight = (currentx >= 200 && currentx < 270 && currenty >= 155 && currenty <= 210);
if (WindowRight)
{
winright = true;
repaint();
}

else;
}

public void mouseReleased(MouseEvent e)
{
}

public void mouseEntered(MouseEvent e)
{
}

public void mouseExited(MouseEvent e)
{
}
}
}

Explanation / Answer

please rate - thanks

sorry I don't know how to do sound

import java.awt.*;
import java.applet.*;
import java.awt.event.*;

public class HouseTestB extends Applet
{
boolean winleft, winright, roof, base, door;
public void init()
{
winleft = winright=roof = base = door = true;
setBackground(Color.WHITE);
addMouseListener(new MyMouseListener());
}

public void paint(Graphics g)
{

super.paint(g);
// roof

if (roof)
{
g.fillPolygon(new int[] {156,0,299}, new int[] {99,150,150}, 3);
}

if (winleft)
{
g.fillRect(50, 155, 50, 70);
}
else
{// window left

    g.drawLine(156, 99, 0, 150);
    g.drawLine(156, 99, 299, 150);
    g.drawLine(0, 150, 299, 150);
    }
if (winright)
{
g.fillRect(200, 155, 50, 70);
}
else
    {// window right
    g.drawRect(200, 155, 50, 70);
    g.drawLine(200, 185, 250, 185);
    g.drawLine(225, 155, 225, 225);
    }
if (door)
{
g.fillRect(120, 155, 50, 100);
}
else
    {// door
    g.drawRect(120, 155, 50, 100);
    g.fillOval(158, 200, 5, 10);
    }

// base
g.drawRect(3, 150, 296, 110);


g.drawRect(50, 155, 50, 70);
g.drawLine(50, 185, 100, 185);
g.drawLine(75, 155, 75, 225);



}

private class MyMouseListener implements MouseListener
{
public void mousePressed(MouseEvent e)
{
}

public void mouseClicked(MouseEvent e)
{
int currentx = e.getX();
int currenty = e.getY();

boolean WindowLeft = (currentx >= 50 && currentx < 77 && currenty >= 155 && currenty <= 225);
if (WindowLeft)
{
winleft = false;
repaint();
}

boolean Roof = (currentx >= 0 && currentx < 299 && currenty >= 99 && currenty <= 150);
if (Roof)
{
roof = true;
repaint();
}

boolean Door = (currentx >= 120 && currentx < 170 && currenty >= 155 && currenty <= 255);
if (Door)
{
door = false;
repaint();
}

boolean WindowRight = (currentx >= 200 && currentx < 270 && currenty >= 155 && currenty <= 210);
if (WindowRight)
{
winright = false;
repaint();
}


}

public void mouseReleased(MouseEvent e)
{
}

public void mouseEntered(MouseEvent e)
{
}

public void mouseExited(MouseEvent e)
{
}
}
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote