//************************************
//
// CSC112b Spring 1999
// Ileana Streinu
//
// Java applet for illustrating a simple 
// user-defined class
//
//************************************

import java.applet.*;	// used for applets 
import java.awt.*;	// if you use any kind of graphics
import java.io.*;	// if you use any kind of I/O

// import java.util.*;	// more advanced, not used now
// import java.lang.*;	// more advanced, not used now


//*************************
//
//	myApplet
//
//  The applet draws a small black spot
//  when the user clicks with the mouse
//  on the screen.
//
//  The user-defined class is called myPoint, 
//  to distinguish it from the Java in-built
//  class named Point.
//
//************************

public class myApplet extends Applet
{

myPoint current, mirror; // a point and its mirror image

Button buttonColor;
Button buttonShape;

int theColor;
int theShape;

//************
//
//  init
//
//
//************


public void init() 
{

setBackground(Color.yellow);

buttonColor = new Button("Color");
add(buttonColor);
buttonShape = new Button("Shape");
add(buttonShape);

theColor = 0;
theShape = 0;

}// end init

//*************************
//
//  action
//
//*************************


public boolean action(Event e, Object o)
{
if(e.target==buttonColor)
        theColor = ++theColor % 2;
if(e.target==buttonShape)
        theShape = ++theShape % 2;
return true;
}// end action



//*****************************
//
//     mouseDown
//
//  mouse action - when pressing the mouse button
//
//*****************************


public boolean mouseDown(Event e, int x, int y)
{

// create two identical points

current = new myPoint(x,y,theColor, theShape);
mirror = new myPoint(x,y,theColor, theShape);

// then translate mirror 50 pixels in both directions
// move is a method inherited from the class Point

mirror.move(x+50, y+50); // here we use the method translate
			  // inherited from the class Point

// are these points equal? They should not be. The test is 
// here just to exemplify the method equals

if (current.equals(mirror)) System.out.println("Equal");
else System.out.println("Not Equal");

repaint();

return true;
}


//******************************************
//
//    paint
//
// What is executed when the applet is repainted
//
//*******************************************

public void paint(Graphics g)
{

if(current != null)
{
current.Print();
current.Draw(g);
mirror.Print();
mirror.Draw(g);
g.drawString(mirror.toString(),mirror.x, mirror.y);
}


}//end of method paint



}// end myApplet


