import java.awt.*;

import java.awt.event.*;

import javax.swing.*;

import java.util.*;


   Display houses by pressing mouse with random color & width

   while blinking 3 colored windows.

   @author Kathleen O'Brien updated by Ahmad Mobasseri


public class HouseAnimationFrame extends JFrame


   private HousePanel panel;              // Customized panel which extends JPanel

   private static final long serialVersionUID = 1;


   public HouseAnimationFrame()                 // Constructor


     setTitle("The Houses with blinking lights");



     panel = new HousePanel();                  // Call HousePanel const. to start building a house




//------------inner class HousePanel-------------------

   class HousePanel extends JPanel implements MouseListener


      private final int WIDTH_MAX = 70;  

      private final int WIDTH_MIN = 20;

      private static final long serialVersionUID = 1;


      private HousePanel()                                  // Constructor



          addMouseListener(this);                     // Mouse Event         



/***      public void paintComponent(Graphics g)// NOTE, no need as no drawing here.



      }  ***/


      public void mousePressed (MouseEvent e)   // Mouse Event handler


        int x = e.getX();

        int y = e.getY();

        Random random = new Random();                 // Random color and width for each house

        Color randColor = new Color(random.nextInt(256), random.nextInt(256), random.nextInt(256));

        int randWidth = (int) (Math.floor(Math.random() * (WIDTH_MAX - WIDTH_MIN +1)) + WIDTH_MIN);

        new AnimatedHouse(panel, x, y, randColor, randWidth).start();   // Build a house for each mouse pressed


      public void mouseClicked  (MouseEvent e) {};          // These Events of mouse are not used

      public void mouseReleased (MouseEvent e) {};

      public void mouseEntered  (MouseEvent e) {};

      public void mouseExited   (MouseEvent e) {};

   }//end HousePanel ---------------------------------


   // Start the program by creating instance of this class (extends JFrame)

   public static void main(String[] args)


      JFrame myFrame = new HouseAnimationFrame();




}//end HouseAnimationFrame ---------------------------------