954,536 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Need help with my java Homework

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);
            	}
       	 	}
    		}
}
kingofdrew
Newbie Poster
4 posts since Feb 2011
Reputation Points: 10
Solved Threads: 0
 

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.

kingofdrew
Newbie Poster
4 posts since Feb 2011
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: