package lab10;

import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;

import javax.swing.Action;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;

public class TicTacToeMain extends JFrame{

	/**
	 * constructor
	 */
	public TicTacToeMain(){
		super("TicTacToe");
		build();
	}

	/**
	 * build the window
	 */
	void build(){
		setLocationRelativeTo(null);
		setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
		setVisible(true);
		setSize(300, 300);

		final TicTacToeNav nav = new TicTacToeNav(){
			//preinited panel
			private JPanel _single = new TicTacToeMenu(this),
					       _two = new TicTacToeMenu(this),
					       _score = new TicTacToeStat(this),
					       _about = new TicTacToeAbout(this),
					       _quit = new TicTacToeQuit(this),
					       _end = new TicTacToeEnd(this),
					       _title = new TicTacToeTitle(this);
			//method
			/* (non-Javadoc)
			 * @see lab10.TicTacToeNav#singlePlayer()
			 */
			public void singlePlayer() {
				setContentPane(_single);
				_single.requestFocus();
				revalidate();
			}
			/* (non-Javadoc)
			 * @see lab10.TicTacToeNav#twoPlayer()
			 */
			public void twoPlayer() {
				setContentPane(_two);
				_two.requestFocus();
				revalidate();
			}
			/* (non-Javadoc)
			 * @see lab10.TicTacToeNav#stat()
			 */
			public void stat() {
				setContentPane(_score);
				_score.requestFocus();
				revalidate();
			}
			/* (non-Javadoc)
			 * @see lab10.TicTacToeNav#about()
			 */
			public void about() {
				setContentPane(_about);
				_about.requestFocus();
				revalidate();
			}
			/* (non-Javadoc)
			 * @see lab10.TicTacToeNav#title()
			 */
			public void title() {
				setContentPane(_title);
				_title.requestFocus();
				revalidate();
			}
			/* (non-Javadoc)
			 * @see lab10.TicTacToeNav#quit()
			 */
			public void quit() {
				setContentPane(_quit);
				_single.requestFocus();
				revalidate();
			}
			/* (non-Javadoc)
			 * @see lab10.TicTacToeNav#win()
			 */
			public void win() {
				setContentPane(_end);
				_single.requestFocus();
				revalidate();
			}
			/* (non-Javadoc)
			 * @see lab10.TicTacToeNav#exit()
			 */
			public void exit(){
				setVisible(false);
				dispose();
			};
		};

		addWindowListener(new WindowListener(){
			public void windowActivated(WindowEvent arg0) {}
			public void windowClosed(WindowEvent arg0) {}
			public void windowClosing(WindowEvent arg0) {
				nav.quit();
			}
			public void windowDeactivated(WindowEvent arg0) {}
			public void windowDeiconified(WindowEvent arg0) {}
			public void windowIconified(WindowEvent arg0) {}
			public void windowOpened(WindowEvent arg0) {}
		});

		nav.title();
	}

	/**
	 * @param args
	 */
	public static void main(String [] args){
		TicTacToeMain tmp = new TicTacToeMain();
	}
}
