/** Use JWS to modify MyApplet8.java (previously SimpleApplet6.java) 
 ** by changing it to paint a different colored shape not centered on 
 ** the tip of the pointer, in response to mouseDown events. You might 
 ** also decide to add some other unusual (weird?) behavior to entertain 
 ** (befuddle?) the user.  Also, edit MyApplet8.html in the  project 
 ** directory, both to run the MyApplet8.class file you create, and so 
 ** that everything looks nice and works properly.                    **/
 
/** USE EXISTING JAVA CLASSES **/

import java.awt.*;
import java.applet.Applet;

/** EXTEND THE JAVA APPLET CLASS **/

public class MyApplet8 extends Applet 
   {final int maxnumspots = 30;                       // Define max number of spots,
    final int maxnumevents = maxnumspots + 10;         // max number of events, 
    int xevent[] = new int[maxnumevents];             // array of xcoords. of events,
    int yevent[] = new int[maxnumevents];             // array of ycoords. of events, 
    int curevent = 0;                                 // and the current event number. 
						      // Note that Java starts numbering
    public void init()	                              // with 0, instead of 1.
       {setBackground(Color.black);}             // Change the gray background to white.
       
    /** HANDLE MOUSEDOWN EVENT **/    
    
     public boolean mouseDown(Event e, int x, int y)
	{if (curevent < maxnumevents)                 // If the current event number
	  {addspot(x,y);                              // (e.g. 0-24) is less than the 
	   return true;}                              // max number of events (e.g. 25),
	 else                                         // then call the addspot method.
	  {return false;}      
	 }
	
     /** REPAINT THE FRAME USING THE ADDSPOT METHOD **/   
     
     void addspot(int x, int y)
	{xevent[curevent] = x;                        // Record the xcoord. and ycoord.
	 yevent[curevent] = y;                        // of the current event.
	 curevent++;                                  // Add 1 to the current event number.
	 repaint();                                   // Call the paint method.
	 }
	      
    /** CREATE THE CURRENT FRAME **/

    public void paint(Graphics g)
       {g.setColor(Color.green);
	for (int i = 0; i < curevent; i++)    // Note that nothing happens here, until a
	  {if (i < maxnumspots)               // mouseDown event occurs. Repaint all spots 
	    {g.fillOval(xevent[i] - 10,yevent[i] - 1,1,1);} // from 0 to maxnumspots-1, each
	   else                                                // centered on the mouse pointer.
	    {g.setColor(Color.blue);           // Also, if curevent > maxnumspots, then print
	     g.drawString("Stop it !!",xevent[i],yevent[i]);}  // this too.
	   }
	}
    }		 