My homework is
Write an applet that draw the house shown on the left in Figure 14-32. When the user clicks on the door or windows, they should close. The figure on the right shows the house with its door and windows closed.
I basic want a java applet that if a user clicks on a rectangle another one is sudden created and drawn.
import javax.swing.*;
import java.awt.*;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
public class test7 extends JFrame
{
private JFrame frame;
public void init()
{
final Component trayicon = null;
final Component trayicon2 = extracted(trayicon);
extracted(trayicon2).addMouseListener(new click());
}
private Component extracted(final Component trayicon2) {
return trayicon2;
}
public void paint (Graphics g)
{
super.paint(g);
g.drawRect(100, 100, 100, 100);
}
private class click extends MouseAdapter
{
public void mouseEntered(final MouseEvent e)
{
if (frame.addComponentListener(null))
g.drawRect(150, 50, 500, 300);
{
frame.setVisible(true);
}
}
}
}