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);
            	}
       	 	}
    		}
}

The problem is how do you create if statement that allows a action listener. I want to allow a user to make a if statement that they selects a component an action happens. I don't know were to find the answer. for example if (frame,isSelected()) draw.rect
my problem is i don't know how to do this with a applet or action handler.

This article has been dead for over six months. Start a new discussion instead.