import java.awt.*;
import java.awt.event.*;
import java.awt.*;
import java.applet.*;
import java.io.*;
import java.lang.*;
import java.util.*;

class Morph extends Frame
 implements MouseListener, MouseMotionListener {
	
	int mouseX, mouseY;
 	boolean initialised = false;
	
	public void init() {
		addMouseListener(this);
		addMouseMotionListener(this);
		inf.draw(this.getGraphics());
	}
	
	// Handle mouse clicked.
	public void mouseClicked(MouseEvent me) {
		//me.consume();
		inf.handleMouseClick(me,this.getGraphics());
	}
	
	// Handle mouse entered.
	public void mouseEntered(MouseEvent me) {
		inf.draw(this.getGraphics());
		// System.out.println("MouseEntered");
		// System.out.println(me);
	}
	
	// Handle mouse exited.
	public void mouseExited(MouseEvent me) {
		
	}
	
	boolean mouseRel = true;
	  // Handle button pressed.
	public void mousePressed(MouseEvent me) {
		// repaint();
		// inf.handleMouseClick(me,this.getGraphics());	  
	}
	
	// Handle button released.
	public void mouseReleased(MouseEvent me) {
		// save coordinates
		mouseX = me.getX();
		mouseY = me.getY();
		
		mouseRel = true;
	}
	
	// Handle mouse dragged.
	public void mouseDragged(MouseEvent me) {
		// save coordinates
		mouseX = me.getX();
		mouseY = me.getY();
	}
	
	// Handle mouse moved.
	public void mouseMoved(MouseEvent me) {
		inf.handleMouseOver(me,this.getGraphics());
	}
	
	public void delay(long ms) { 
		try { 
			Thread.sleep(ms);
		} 
		catch(InterruptedException e) { } 
	}
	
	public void initialise(Graphics g)
	{
		inf.draw(g);
//		fe.addMouseMotionListener(this);
//		ButtonListener = new bhandler();
//		ButtonListener.SetNumberOfButtons(10);
	}
	
	Interface inf = new Interface();
	
	public static Morph morph;
	public void setNorm() {
		inf.setNorm(getGraphics());
	}

	public void paint(Graphics g)
	{
		if(initialised == false) { initialise(g);initialised=true;}
		inf.draw(g);
	}
	
	public Morph() {
		morph = this;
		
		this.addMouseListener(this);
		this.addMouseMotionListener(this);
		
		
	}
	
	public static void main(String args[]) {
		// System.out.println("Starting Morph...");
		Md2 md2Frame = new Md2();
		md2Frame.setSize(800, 570);
		md2Frame.setTitle("Model Animation Demo");
		
		Morph mainFrame = new Morph();
		mainFrame.setTitle("Polygon morphing");
		
		Md2.morphFrame = mainFrame;
		Md2.md2Frame = md2Frame;
		
		WindowListener l = new WindowAdapter() {
			public void windowClosing(WindowEvent e) {
				System.exit(0);
			}
		};
      	mainFrame.addWindowListener(l);
      	mainFrame.setBackground(Color.white);
		mainFrame.setSize(800, 600);
		mainFrame.setVisible(true);
		mainFrame.delay(300);
		mainFrame.inf.draw(mainFrame.getGraphics());
		// mainFrame.paint(mainFrame.getGraphics());
		// 581 x 273 == drawing area
		// begins at (99, 223)
	}
	
}
