package swingUI;

import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.Reader;

import javax.swing.AbstractAction;
import javax.swing.JButton;
import javax.swing.JPanel;
import javax.swing.JTextArea;

/**
 * @author martin
 * about TicTacToe screen
 */
public class TicTacToeAbout extends JPanel{
	/**
	 * @param nav as JFrame navigator
	 */
	public TicTacToeAbout(final TicTacToeNav nav){
		super(new BorderLayout());
		setFocusable(true);

		//text area, load from 'about.txt'
	    String about = new String();
	    try {
			Reader in = new BufferedReader(new FileReader("about.txt"));
			while(in.ready())
				about = about + (char)in.read();
		} catch (FileNotFoundException e1) {
			about = "error with 'about.txt'";
		} catch (IOException e1) {
			about = "error with 'about.txt'";
		}
	    add(new JTextArea(about), BorderLayout.CENTER);

	    //button return to title screen
	    add(new JButton( new AbstractAction("return to Title"){
			public void actionPerformed(ActionEvent e) {
				nav.title();
			}
	    }), BorderLayout.SOUTH);

	    //key listener
	    addKeyListener( new KeyListener(){
	    	public void keyPressed(KeyEvent e) {
	    		if (e.getKeyCode()==KeyEvent.VK_T)
	    			nav.title();
	    	}
	    	public void keyReleased(KeyEvent e) {}
	    	public void keyTyped(KeyEvent e) {}
	    });
	}
}
