public GameWindow() {
		// getContentPane().setBackground(new Color(51, 153, 255));

		/*
		 * pg.addKeyListener(new KeyAdapter() {
		 * 
		 * public void keyPressed(KeyEvent arg0) {
		 * 
		 * int keycode = arg0.getKeyCode();
		 * 
		 * System.out.println("" + keycode); ks.setKeypressed(keycode);
		 * 
		 * 
		 * 
		 * /* if (keycode != 32 && (keycode < 37 || keycode > 40)) return;
		 * 
		 * cmd = "MOVE:" + gameClientHandler.game.getGameid() + ":" + keycode +
		 * "\r\n";
		 * 
		 * EventQueue.invokeLater(new Runnable() { public void run() {
		 * sendMessage(); } });
		 */

		/*
		 * class KeyPressTask extends TimerTask { private int keycode;
		 * 
		 * public KeyPressTask(int code) { keycode = code; }
		 * 
		 * public void run() { cmd = "MOVE:" +
		 * gameClientHandler.game.getGameid() + ":" + keycode + "\r\n";
		 * 
		 * // EventQueue.invokeLater(new Runnable() { // public void run() {
		 * sendMessage();
		 * 
		 * 
		 * // } // }); timer.schedule(this, 200); }
		 * 
		 * }
		 * 
		 * KeyPressTask tt = new KeyPressTask(keycode); timer.schedule(tt, 200);
		 */
		// }

		// public void keyReleased(KeyEvent arg0) {
		//
		// int keycode = arg0.getKeyCode();

		// System.out.println("" + keycode);
		//
		// ks.setKeyreleased(keycode);

		/*
		 * if (keycode != 32 && (keycode < 37 || keycode > 40)) return;
		 * 
		 * cmd = "MOVE:" + gameClientHandler.game.getGameid() + ":" + keycode +
		 * "\r\n";
		 * 
		 * EventQueue.invokeLater(new Runnable() { public void run() {
		 * sendMessage(); } });
		 */

		/*
		 * class KeyPressTask extends TimerTask { private int keycode;
		 * 
		 * public KeyPressTask(int code) { keycode = code; }
		 * 
		 * public void run() { cmd = "MOVE:" +
		 * gameClientHandler.game.getGameid() + ":" + keycode + "\r\n";
		 * 
		 * // EventQueue.invokeLater(new Runnable() { // public void run() {
		 * sendMessage();
		 * 
		 * 
		 * // } // }); timer.schedule(this, 200); }
		 * 
		 * }
		 * 
		 * KeyPressTask tt = new KeyPressTask(keycode); timer.schedule(tt, 200);
		 */
		// }

		// });*/

		this.getContentPane().add(pg);
		pg.requestFocusInWindow();

		b.group(group).channel(NioSocketChannel.class)
				.handler(new gameClientInitializer(this));

		// Start the connection attempt.

		// System.out.println(dialog.getOwner().getClass());

		try {
			channel = b.connect(HOST, PORT).sync().channel();

			while (!AGameSession.isGotGames())
				;
			DlgMain dialog = new DlgMain(this, true);
			dialog.setTitle("Larser-War Game");
			dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);

			DlgList dialogList = new DlgList();
			dialogList.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);

			dialog.setVisible(true);

			if (dialog.gameWay.equals("NEW"))
				gameClientHandler.game.ID = 1;
			else
				gameClientHandler.game.ID = 2;

			if (gameClientHandler.game.ID == 1)
				lastWriteFuture = channel.writeAndFlush("NEWGAME\r\n");
			else {

				dialogList.putAllGames();
				dialogList.setVisible(true);

				gameClientHandler.game.setGameid(dialogList.gameid);

				lastWriteFuture = channel.writeAndFlush("JOIN:"
						+ gameClientHandler.game.getGameid() + "\r\n");

			}

		} catch (Exception e) {
			e.printStackTrace();
			return;
		}

		addWindowListener(new WindowAdapter() {
			@Override
			public void windowClosing(WindowEvent arg0) {

				try {
					// channel.closeFuture().sync();
					timer.stop();
					if (lastWriteFuture != null)
						lastWriteFuture.sync();

				} catch (Exception e) {
					System.out.println(e);
				} finally {
					group.shutdownGracefully();
				}

			}
		});
		setResizable(false);
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		// setBounds(10, 10, 1200, 800);

		// keyTimer.schedule(new TimerTask(), time);

		timer = new Timer(50, this);

		timer.start();

	}