/*  Graffiti 1.2: An Intereactive Color Drawing Program by Lisa Gade.  5/25/97
  Using MetroWorks CodeWarrior Pro2 for Mac 
  Updated 3/22/98 to add the clear button and a few more color choices- wowee kazowee ;-)*/
 
import java.awt.*;
import java.applet.*;

public class ClrDrawApplet extends Applet{
private Choice  colorChoice;
private Image background;
Graphics g;
AudioClip dont;
Rectangle rwin=new Rectangle (290,245,40,30);
Button b;
//-------------------------------------------------------------------
public void init() {

	resize(400,285);
   g=getGraphics();

g.drawRect(rwin.x,rwin.y,rwin.width,rwin.height);
dont=getAudioClip(getDocumentBase(), "dont.au");

background=this.getImage(this.getDocumentBase(), "brick_wall2.gif");
Image offScrImage=createImage(size().width, size().height);
Graphics offScrGC=offScrImage.getGraphics();
offScrGC.drawImage(background,0,0,this);


//set up the color choices in the pane:
 colorChoice = new Choice();
      colorChoice.addItem("Red");
      colorChoice.addItem("Green");
      colorChoice.addItem("Black");
      colorChoice.addItem("Yellow");
      colorChoice.addItem("Blue");
      colorChoice.addItem("Cyan");
      colorChoice.addItem("Magenta");
      colorChoice.addItem("Orange");

      add(colorChoice);  //adds all those nice color choices to the pane
      
//set up the "clear" button in the pane:
		b=new Button("Clear");
		add (b);
    }
    
     //--Clear Button event creation-----------------------------
   
    public boolean action(Event e_button, Object arg) {
    if (e_button.target == b){
    		g.drawImage(background, 0,0, null);
    return true;
    }
    else return false;
    }

    //-------------------------------------------------------------------

    
 public boolean mouseDown(Event e, int x, int y) {
 String colorString = colorChoice.getSelectedItem();
      
       if (colorString.equals("Red"))
         color = Color.red;
      else if (colorString.equals("Green"))
        color = Color.green;
      else if (colorString.equals("Black"))
        color = Color.black;
         else if (colorString.equals("Yellow"))
        color = Color.yellow;
         else if (colorString.equals("Cyan"))
        color = Color.cyan;
         else if (colorString.equals("Magenta"))
        color = Color.magenta;
         else if (colorString.equals("Orange"))
        color = Color.orange;
         else
        color = Color.blue;  
        
         return true;
 }
 
 //-------------------------------------------------------------------------------- 
        
protected Color color;
 
		private int x=0; private int y=0;	//mouse coordinates
//automatically called when mouse button is depressed:
		public boolean mouseMove(Event anEvent, int aX, int aY){
		x=aX;y=aY;	//sets mouse coords
		return true;}
//-------------------------------------------------------------------------------- 

public boolean mouseDrag(Event anEvent, int aX,int aY){
 
	Graphics g=this.getGraphics();	//create graphic object
	g.setColor(this.color);
		g.drawLine(x,y,aX,aY);	//straight line from (x,y)to(aX,aY), in parallel 3x for thicker line
		g.drawLine(x+1,y+1,aX+1,aY+1);
		g.drawLine(x+2,y+2,aX+2,aY+2);

		x=aX;y=aY;//update mouse position
	
		return true;
	}
//_______________________________________________________________
	
	 public boolean handleEvent(Event e_speak) {
	 if (e_speak.id == Event.MOUSE_DOWN) { 
	     if (rwin.inside(e_speak.x, e_speak.y))
	 {
		dont.play();
		showStatus ("Lisa WUZ here!");		
		}
	}
	return super.handleEvent(e_speak);
	}
//_______________________________________________________________
public boolean imageUpdate (Image img, int infoflags, int x, int y, int w, int h)
{
		if (infoflags==ALLBITS) {
			repaint();
		return false;
	}
		else
		return true;
	}


//________________________________________________________________     
	
	public void paint(Graphics g) {
		showStatus("Graffitti: running");
		g.drawImage(background, 0,0, null);
		g.setColor(Color.red);	
	}
}


