// package PongishGame;
import edu.neu.ccs.gui.*;
import edu.neu.ccs.jpf.*;
import edu.neu.ccs.util.*;
import java.awt.event.*;
import java.awt.*;

public class Pong extends JPF implements JPTConstants, WindowListener{
    int screenLen = 800; //canvas width/height ( must be sqare)
	Mover m;             //the current Mover object 

    DisplayPanel main;
    JPTFrame frame;
    BufferedPanel b = new BufferedPanel(screenLen, screenLen);

	public static void main(String args[]){
		new Pong();
	}

    //methods to run the demos
    public void startDemo0(){
        m = new Mover(screenLen, screenLen, b);
        animate();
    }

    //called when window has been resized
    private void resized(){
    	Dimension newDim = new Dimension(this.frame.getWidth(), this.frame.getHeight() - 50);
    	m.resized(newDim);
    	b.setBufferSize(newDim);
    	Refresh.packParentWindow(b);
    }
    
	//called to start a new animation window
    private void animate(){
        frame = b.frame();
        frame.addWindowListener(this);
		frame.addComponentListener(
				new ComponentListener() {
					public void componentResized(ComponentEvent e) {
						resized();
			        }
			        public void componentMoved(ComponentEvent e) {}
			        public void componentHidden(ComponentEvent e) {}
			        public void componentShown(ComponentEvent e) {}
				}
		);
        m.newGame();
    }
    
    //called to stop the animation
    public void stopAnimation(){
    	m.stop();
    	m = null;
    }

    //Window listeners to stop thread when window is closed
	public void windowClosing(WindowEvent arg0) {
		stopAnimation();
	}
	public void windowClosed(WindowEvent arg0) {}
	public void windowOpened(WindowEvent arg0) {}
	public void windowIconified(WindowEvent arg0) {}
	public void windowDeiconified(WindowEvent arg0) {}
	public void windowActivated(WindowEvent arg0) {}
	public void windowDeactivated(WindowEvent arg0) {}
}
