/** Use JWS to modify MyApplet9.java (previously SimpleApplet7.java) 
 ** by changing it to definitely have some different (weird?) behavior 
 ** to entertain (befuddle?) the user.  Also, edit MyApplet9.html in 
 ** the project directory, both to run the MyApplet9.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 MyApplet9 extends Applet 
   {final int maxnumlines = 15;                       
    final int maxsize = maxnumlines + 5;              
    Point startpoint[] = new Point[maxsize];         
    Point endpoint[] = new Point[maxsize];           
    Point anchorpoint, connectpoint;                 
        int entrynum = 0;                                 
						      
						      
    public void init()	                      
       {setBackground(new Color (100,0,100));}             
       
     /** HANDLE THE MOUSEDOWN EVENT **/    
    
     public boolean mouseDown(Event e, int x, int y)
	{if (entrynum < maxsize)                 
	  {anchorpoint = new Point(x,y);              
	   connectpoint = anchorpoint;                 
	   return true;}                             
	 else                                        
	  {return false;}                            
	 }
	 
     /** HANDLE THE MOUSEDRAG EVENT **/    
    
     public boolean mouseDrag(Event e, int x, int y)
	{if (entrynum < maxsize)                      
	  {connectpoint = new Point(x,y);             
	   repaint();                                 
	   return true;}                              
	 else                                          
	  {return false;}                             
	 }	 
	 	 
	
     /** HANDLE THE MOUSEUP EVENT **/    
    
     public boolean mouseUp(Event e, int x, int y)
	{if (entrynum < maxsize && connectpoint != anchorpoint) 
	  {addline();                                           
	   repaint();                                           
	   return true;}                                        
	    else                                         
	  {return false;}      
	 }
	 
	 
     /** THE ADDLINE METHOD **/   
     
     void addline()
	{startpoint[entrynum] = anchorpoint;          
	 endpoint[entrynum] = connectpoint;           
	 entrynum++;                                  
	 anchorpoint = null;                          
	 connectpoint = null;                                                          
	 }                                            
	      
    /** CREATE THE CURRENT FRAME **/

    public void paint(Graphics g)
       {g.setColor(Color.yellow);
	for (int i = 0; i < entrynum; i++)                    
	  {if (i < maxnumlines)                                
	    {g.drawLine(startpoint[i].x, startpoint[i].y,    
			    endpoint[i].x, endpoint[i].y);}   
	   else                                               
	    {g.setColor(Color.white);                           
	     g.drawString("What a Pretty Picture!!",   
			    endpoint[i].x, endpoint[i].y);}  
	   }
	if (connectpoint != anchorpoint)                     
	 {g.setColor(Color.black);                        
	  g.drawLine(anchorpoint.x, anchorpoint.y, 
		      connectpoint.x, connectpoint.y);}
	}
    }		 