import java.awt.*;
import LocalUtil;

public class Splash extends Thread {
	Frame frame;
	int x, y, dx = 5, dy =5;
	int width, height;
	boolean moving = false;
	Image img;
	Window win;

	public Splash(Frame f) {
		frame = f;

		img = Toolkit.getDefaultToolkit().getImage("MIKE.jpg");
		LocalUtil.waitforimg(f, img);

		win = new Window(frame);

		ImgCanvas can = new ImgCanvas(img);

		win.add(can, "Center");

		Dimension scrn = Toolkit.getDefaultToolkit().getScreenSize();

		width = img.getWidth(frame);
		height = img.getHeight(frame);

		win.setLocation(scrn.width/2 - (width/2),
		                scrn.height/2 - (height/2));

		win.setSize(width, height);
		win.show();
		win.toFront();

		try {
			Thread.currentThread().sleep(100);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	public void run() {

		x = 10;
		y = 10;

		if(moving) {
			for(int i = 0; i < 1000; i++) {
				x += dx;
				y += dy;

				if(x < 0) {
					x = 0;
					dx = -dx;
				}

				if(x >= 640) {
					x = 640;
					dx = (short)-dx;
				}

				if(y < 0) {
					y = 0;
					dy = (short)-dy;
				}	

				if(y >= 480) {
					y = 480;
					dy = (short)-dy;
				}

				win.setLocation(x,y);

				try {
					Thread.currentThread().sleep(20);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		} else {
/*			win.setLocation(scrn.width/3 - (width/3),
			                scrn.height/3 - (height/3));
*/
			try {
				Thread.currentThread().sleep(5000);
			} catch (Exception e) {
				e.printStackTrace();
			}
		}

		win.dispose();
	}
}

class ImgCanvas extends Canvas {
	private Image img;

	public ImgCanvas(Image image) {
		MediaTracker mt = new MediaTracker(this);
		mt.addImage(image, 0);

		try {
			mt.waitForID(0);
		} catch (Exception e) {
			e.printStackTrace();
		}

		img = image;
	}

	public void paint(Graphics g) {
		g.drawImage(img, 0, 0, this);
		g.setColor(Color.white);
		g.drawString("Acts of God(esses)", 120, 20);
		g.drawString("Version .000000001", 120, 40);

		g.drawString("By: Audin Malmin, Chris Corwin, and Onder Ceyhun", 40, 270);
	}

	public void update(Graphics g) {
		paint(g);
	}

	public Dimension preferredSize() {
		return new Dimension(img.getWidth(this), img.getHeight(this));
	}
}

