import javax.swing.*;
import java.awt.*;
// Use this JPanel-extension class to
// redraw a closed-opening house.
public class HouseClosed extends JPanel
{
// Use the constructor to setup the method below.
public HouseClosed()
{
// Make the background white.
setBackground(Color.WHITE);
// Match the html-document version of the applet
// when it comes to size.
setPreferredSize(new Dimension(370, 300));
}
public void paintComponent(Graphics g)
{
super.paintComponent(g);
// Setup the x- and y-coordinates for a triangle-roof.
int[] xCoords = {60, 180, 300};
int[] yCoords = {100, 30, 100};
// Draw the color-filled, house-roof triangle.
g.setColor(Color.RED);
g.fillPolygon(xCoords, yCoords, 3);
// Draw the house-rectangle.
g.setColor(Color.GRAY);
g.fillRect(80, 100, 200, 80);
// Draw the closed-door.
g.setColor(Color.RED);
g.fillRect(160, 120, 40, 60);
// Draw it's knob.
g.setColor(Color.BLACK);
g.fillOval(188, 150, 5, 5);
// Draw the closed-windows.
g.setColor(Color.CYAN);
g.fillRect(100, 120, 36, 36);
g.setColor(Color.CYAN);
g.fillRect(224, 120, 36, 36);
// Draw the window-dividers.
g.setColor(Color.BLACK);
g.drawLine(118, 120, 118, 156);
g.setColor(Color.BLACK);
g.drawLine(100, 138, 136, 138);
g.setColor(Color.BLACK);
g.drawLine(224, 138, 260, 138);
g.setColor(Color.BLACK);
g.drawLine(242, 120, 242, 156);
}
}