0

The following applet that I have displays a house with two windows and a door that are colored in black. I want to display these items with window panes in them to show that they are open when the user clicks on them. I know that I need to use a MouseListener that repaints to do so, but do not understand how to set the right coordinates to make that possible...

package hw13;

import java.awt.event.MouseEvent;
import javax.swing.*;
import java.awt.*;
import java.awt.event.MouseListener;

/**
 * This class is an applet that demonstrates how
 * rectangles can be drawn.
 */

public class Main extends JApplet
{

   public void init()
   {
      // Set the background color to white.
      getContentPane().setBackground(Color.WHITE);  
   
   }
   
  
   public void paint(Graphics g)
   {
      super.paint(g);
      
      g.setColor(Color.BLUE);
      g.fillRect(5, 5 , 200, 150);
      g.setColor(Color.BLACK);
      g.fillRect(20,40,35,35);
      g.setColor(Color.BLACK);
      g.fillRect(140,40,35,35);
      g.setColor(Color.BLACK);
      g.fillRect(75,75,50,80);
   }
   
   
   
   

   
   }
2
Contributors
1
Reply
2
Views
8 Years
Discussion Span
Last Post by Antenka
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.