package swingUI;

import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;

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

/**
 * @author martin
 * quit confirmation
 */
public class TicTacToeQuit extends JPanel{
	/**
	 * @param nav as jframe navigator
	 */
	public TicTacToeQuit(final TicTacToeNav nav){
		super(new GridLayout(3,1));
		setFocusable(true);

		add(new JLabel("Quit ?"));
		//return to title button
		add(new JButton(new AbstractAction("no no i just missclicked !!"){
			public void actionPerformed(ActionEvent e) {
				nav.title();
			}
		}));
		//yes quit
		add(new JButton(new AbstractAction("YES !!! WHY SHOULD I CONFIRM!!!!"){
			public void actionPerformed(ActionEvent e) {
				nav.exit();
			}
		}));
		//keylistener
		addKeyListener(new KeyListener() {
			public void keyTyped(KeyEvent arg0) {}
			public void keyReleased(KeyEvent arg0) {}
			public void keyPressed(KeyEvent arg0) {
				if (arg0.getKeyCode() == KeyEvent.VK_Y)
					nav.exit();
				if (arg0.getKeyCode() == KeyEvent.VK_N)
					nav.title();
			}
		});
	}
}
