@SuppressWarnings("serial")
public class GameLobby extends JPanel implements GameLobbyInter, PanelInterface {

	private UserListFrame userListFrame;
	
	/*
	 * Component of Gamer Panel
	 */
	private JLabel m_roomInfo, m_userInfo1, m_userInfo2;
	
	private JPanel m_gamerPanel = new JPanel() {
		public void paint(Graphics g) {
			this.paintComponents(g);
		}
	};

	private ImageButton m_gamer1Button, m_gamer2Button;

	/*
	 * Component of User List Panel
	 */
	private JPanel m_userListPanel = new JPanel() {
		public void paint(Graphics g) {
			this.paintComponents(g);
		}
	};

	private JList m_userList = new JList();

	private JScrollPane m_scPaneUserList;

	/*
	 * Component of Chat Window
	 */
	private JPanel m_logWinPanel = new JPanel() {
		public void paint(Graphics g) {
			this.paintComponents(g);
		}
	};

	private JTextArea m_logWindow = new JTextArea(5, 20);

	private JTextField m_textInput = new JTextField();

	private ImageButton m_sendButton = new ImageButton("image/gameLobbySendButton.jpg", "SEND", "image/gameLobbySendButtonOver.jpg");

	private JScrollPane m_scPaneLogWin;
	private JScrollBar m_vScroll;

	/*
	 * Component of Info Panel
	 */
	private JPanel m_infoPanel = new JPanel() {
		public void paint(Graphics g) {
			this.paintComponents(g);
		}
	};

	private ImageButton m_exitButton = new ImageButton("image/gameLobbyExitButton.jpg", "나가기", "image/gameLobbyExitButtonOver.jpg");
	private ImageButton m_totalUserButton = new ImageButton("image/gameTotalUserButton.jpg","Total User", "image/gameTotalUserButtonOver.jpg");
	
	protected AbstractButton m_startButton;
	
	/*
	 * 임시...
	 */
	private Vector<String> vc = new Vector<String>();
	
	
	private ClientInterface client;
	private EventExecute event;

	
	private boolean isRoomKing = true;
	/*
	 *  Constructor
	 */
	public GameLobby(ClientInterface client, boolean isRoomKing) {
		
		this.client = client;
		this.event = new EventExecute(this, this.client);
		this.isRoomKing = isRoomKing;
		
		execute();
		
		System.out.println("게임방 생성.");
	}
	
	public static void main(String[] args) {
		JFrame frame = new JFrame("Network FIve Eyes Ver. 1.0");
		Container cp = frame.getContentPane();
		cp.add(new GameLobby(null, true));
		
		frame.setSize(340,440);
		frame.setVisible(true);
		
		frame.addWindowListener(new WindowAdapter() {
			public void windowClosing(WindowEvent e) {
				System.exit(0);
			}
		});
		System.out.println("Exit");
	}
	
	private void execute() {
		add(generatorGamerPanel());
		add(generatorUserListPanel());
		add(generatorChatWindowPanel());
		add(generatorInfoPanel());
		setLayout(null);
	}
	
	public void paint(Graphics g) {
		ImageIcon icon = new ImageIcon(
				URLGetter.getResource("image/gameLobbyBg.jpg"));
		g.drawImage(icon.getImage(),0,0,null,null);
		this.paintComponents(g);
	}
	
	private JPanel generatorGamerPanel() {
		m_roomInfo = new JLabel();
		m_userInfo1 = new JLabel();
		m_userInfo2 = new JLabel();
		
		m_gamer1Button = new ImageButton("image/user1.jpg", "Empty!");
		m_gamer2Button = new ImageButton("image/user2.jpg", "Please Wait....");
		
		m_gamerPanel.add(m_roomInfo);
		m_roomInfo.setBounds(5,5,200,10);
		
		m_gamerPanel.add(m_userInfo1);
		m_userInfo1.setBounds(50,200,100,10);
		m_gamerPanel.add(m_gamer1Button);
		m_gamer1Button.setBounds(40,50, 100,130);
//		m_gamer1Button.setIcon(new ImageIcon(StoneFactory.getInstance().getStone(0)));
		
		m_gamerPanel.add(m_userInfo2);
		m_userInfo2.setBounds(210,200,100,30);
		m_gamerPanel.add(m_gamer2Button);
		m_gamer2Button.setBounds(170, 50, 100, 130);
//		m_gamer2Button.setIcon(new ImageIcon(StoneFactory.getInstance().getStone(1)));
		
		m_gamerPanel.setLayout(null);
		m_gamerPanel.setBounds(5,5,300,245);
//		m_gamerPanel.setBorder(new TitledBorder("sdfsdf"));
			
		return m_gamerPanel;
	}
	
	private JPanel generatorUserListPanel() {
		m_userList.setListData(vc);

//		m_scPaneUserList = new JScrollPane(m_userList,
//				JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
//				JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
//		m_scPaneUserList.setBorder(new TitledBorder("관전자"));
//		m_scPaneUserList.setBounds(5, 5, 220, 90);
		
		
		
//		m_userListPanel.add(m_scPaneUserList);
		m_userListPanel.setLayout(null);
		m_userListPanel.setBounds(270, 5, 230, 130);
//		m_userListPanel.setBorder(new TitledBorder("Sdfsd"));
		
		return m_userListPanel;
	}

	private JPanel generatorChatWindowPanel() {
		m_scPaneLogWin = new JScrollPane(m_logWindow,
				JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
				JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
//		m_scPaneLogWin.setBorder(new TitledBorder("Chatting Window"));
		m_logWindow.setEditable(false);
		m_scPaneLogWin.setBounds(5,5,250,100);
		m_logWindow.setLineWrap(true);
		
		m_vScroll = m_scPaneLogWin.getVerticalScrollBar();
		m_vScroll.addAdjustmentListener(new AdjustmentListener() {
			public void adjustmentValueChanged(AdjustmentEvent e) {
//				System.out.println("************** EVENT!!!" + e.getValueIsAdjusting());
				if(!e.getValueIsAdjusting()) m_vScroll.setValue(m_vScroll.getMaximum());
//				m_vScroll.removeAdjustmentListener(this);
				
			}
		});
		
		m_logWinPanel.add(m_textInput);
		m_textInput.setBounds(5, 110, 180, 30);
		m_logWinPanel.add(m_sendButton);
		m_sendButton.setBounds(195, 110, 60, 30);
		

		m_logWinPanel.add(m_scPaneLogWin);
		m_logWinPanel.setLayout(null);
		m_logWinPanel.setBounds(5, 250, 260, 200);
//		m_logWinPanel.setBorder(new TitledBorder("Sdfsd"));
		
		m_textInput.addActionListener(event);
		m_sendButton.addActionListener(event);
		
		return m_logWinPanel;
	}

	private JPanel generatorInfoPanel() {
//		if(isRoomKing)
			m_startButton = new ImageButton("image/startButton.jpg", "START!", "image/startButtonOver.jpg");
//		else
//			m_startButton = new ImageButton("image/readyButton.jpg", "READY", "image/readyButtonOver.jpg");
		m_infoPanel.add(m_startButton);
		m_startButton.setBounds(5,50,60,40);
		m_infoPanel.add(m_exitButton);
		m_exitButton.setBounds(5,95,60,40);
		
		m_infoPanel.add(m_totalUserButton);
		m_totalUserButton.setBounds(5,5,60,40);
		m_totalUserButton.addActionListener(event);
		
		m_infoPanel.setLayout(null);
		m_infoPanel.setBounds(260, 250, 230,200);
		
//		m_infoPanel.setBorder(new TitledBorder("Sdfsd"));
		
		m_startButton.addActionListener(event);
		m_exitButton.addActionListener(event);
		
//		setClickable(false);
		
		return m_infoPanel;
	}

	public void setClickable(boolean b) {
		m_startButton.setEnabled(b);
	}

	public void setTextToLogWindow(String str) {
		m_logWindow.append(str);
	}

	public void setUserList(Vector<String> userList) {
		Vector<String> temp = new Vector<String>();
		
		setRoomKing(userList.get(0));

		if(userList.size() < 2)
			setCrhallenger("Pleas wait....");
		else
			setCrhallenger(userList.get(1));
		
		int i = 0;
		for (String user : userList)
			if (i++ > 1) temp.add(user);
		
		m_userList.setListData(temp);
	}

	public void showMessageBox(String sender, String message, boolean option) {
		new SlipFrame(sender, message, false);
	}


	public JList getJList() {
		return m_userList;
	}

	public void unShow() {
		this.setVisible(false);
	}
	
	public String getInputText() {
		return m_textInput.getText();
	}


	public void setTextToInput(String string) {
		m_textInput.setText(string);
	}

	public void setRoomKing(String name) {
		m_userInfo1.setText(name);
		this.repaint();
	}

	public void setCrhallenger(String name) {
		m_userInfo2.setText(name);
		this.repaint();
	}

	public void setGameRoomInf(String info) {
		m_roomInfo.setText(info);
	}

	public void setStartButton(boolean isRoomKing) {
		if (isRoomKing) {
			// when user is king of room, this execute..
			m_startButton.setText("START");
			
			this.setButtonEnable(true);
			
		} else {
			m_startButton.setText("START");
		}
		
	}

	public void setButtonEnable(boolean clickable) {
//		m_startButton.setEnabled(clickable);
		m_startButton.setEnabled(true);
		System.out.println("Clikable******************");
	}

	public void setTotalUser(Vector<String> userList) {
		userListFrame.setUserList(userList);
	}

	public void setUserListFrame(UserListFrame userListFrame) {
		this.userListFrame = userListFrame;
	}
	
	public String getGameInfo() {
		return m_roomInfo.getText() + "|" + m_userInfo1.getText() + "|" + m_userInfo2.getText();
	}

	public void setPanel(PanelInterface panel) {
		// TODO Auto-generated method stub
		
	}

	public int[] getFrameSize() {
		int size[] = {340,440};
		return size;
	}

	public void setPanel(GameLobbyInter panel) {
	}
	public void setPanel(LobbyGuiInter panel) {
	}
	public void setPanel(RoomGuiInter panel) {
	}
} public interface GameLobbyInter extends GuiInterface {

	void setRoomKing(String name);
	void setCrhallenger(String string);
	void setGameRoomInf(String info);
	void setStartButton(boolean isRoomKing);
	void setButtonEnable(boolean clickable);
	String getGameInfo();
	int[] getFrameSize();
	
	
} @SuppressWarnings("serial")
public class GameRoomGui extends JPanel implements RoomGuiInter {

	private UserListFrame userListFrame;
	
	/*
	 *  Left Panel
	 */
	private JLabel m_titleLabel;
	private GameBoardCanvas m_board = new GameBoardCanvas();
	private JTextField m_input;
	private JPanel m_canvasPanel;

	/*
	 * Right Panel 
	 */
	private JPanel m_rightPanel;
	private JTextArea m_log;
	private JList m_userList;
	private JLabel m_gamer1,m_gamer2;
	private ImageButton m_gamerCaptin, m_gamerCrhallenger;
	private ImageButton m_exitButton, m_totalUserButton;
	private ImageButton m_backButton;
	private JScrollPane m_logScrollPan;
	private JScrollBar m_vScroll;
	
	private ClientInterface client;
	private EventExecute event;
	
	public GameRoomGui(ClientInterface client) {
		
		this.client = client;
		this.event = new EventExecute(this, this.client);
		
		execute();
		
	}
	
	public void paint(Graphics g) {
		ImageIcon icon = new ImageIcon(
				URLGetter.getResource("image/gameRoomBg.jpg"));
		g.drawImage(icon.getImage(),0,0,null,null);
		this.paintComponents(g);
	}
	
	private void execute() {
		addCanvas();
		addRightPanel();
	}

	private void addCanvas() {
		m_canvasPanel = new JPanel() {
			public void paint(Graphics g) {
				this.paintComponents(g);
			}
		};
		
		m_canvasPanel.add(m_board);
		m_canvasPanel.setLayout(null);
		m_board.setBounds(5, 5, 590, 593);
		
		add(m_canvasPanel);
		m_canvasPanel.setBounds(5,5,600,700);
//		m_canvasPanel.setBorder(new TitledBorder("sdf"));
		
		setLayout(null);
		
		
	}
	
	private void addRightPanel() {
		// userList don't add.
		m_rightPanel = new JPanel() {
			public void paint(Graphics g) {
				this.paintComponents(g);
			}
		};
		
		m_titleLabel = new JLabel("::: Game Infomation.");
		m_rightPanel.add(m_titleLabel);
		m_titleLabel.setBounds(5,10,200, 25);
		
		m_log = new JTextArea(4,50);
		m_gamer1 = new JLabel();
		m_rightPanel.add(m_gamer1);
		m_gamer1.setBounds(5,220,150,25);
		m_gamer2 = new JLabel();
		m_rightPanel.add(m_gamer2);
		m_gamer2.setBounds(145,220,150,25);
		m_gamerCaptin = new ImageButton("image/user1.jpg", "user1");
		m_gamerCrhallenger = new ImageButton("image/user2.jpg", "user2");
//		m_exitButton = new ImageButton("EXIT GAME");
		m_exitButton = new ImageButton("image/exitButton.jpg", "EXIT GAME", "image/exitButtonOver.jpg");
		
		// 상태창
		m_logScrollPan = new JScrollPane(m_log, 
				JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
				JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
		m_rightPanel.add(m_logScrollPan);
		m_logScrollPan.setBounds(3,280,210,195);
//		m_logScrollPan.setBorder(new TitledBorder("상태창"));
		m_log.setEditable(false);
		m_log.setLineWrap(true);
		m_log.setText("");
		
		m_vScroll = m_logScrollPan.getVerticalScrollBar();
		m_vScroll.addAdjustmentListener(new AdjustmentListener() {
			public void adjustmentValueChanged(AdjustmentEvent e) {
//				System.out.println("************** EVENT!!!" + e.getValueIsAdjusting());
				if(!e.getValueIsAdjusting()) 
					m_vScroll.setValue(m_vScroll.getMaximum());
//				m_vScroll.removeAdjustmentListener(this);
				
			}
		});

		
		m_input = new JTextField(10);
		m_rightPanel.add(m_input);
		m_input.setBounds(4, 482, 210, 30);
		m_input.addActionListener(event);
		
//		m_confirm = new JButton("SEND");
//		m_rightPanel.add(m_confirm);
//		m_confirm.setBounds(165,140,45,25);
//		m_confirm.addActionListener(event);
		
		
//		m_userList = new JList();
//		m_userScrollPan = new JScrollPane(m_userList, 
//				JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
//				JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
//		m_userScrollPan.setBorder(new TitledBorder("관전자"));
//		m_rightPanel.add(m_userScrollPan);
//		m_userScrollPan.setBounds(0,175,210,100);
		
		m_totalUserButton = new ImageButton("image/totalUserButton.jpg", "Total User", "image/totalUserButtonOver.jpg");
		m_rightPanel.add(m_totalUserButton);
		m_totalUserButton.setBounds(5,544,65,44);
		m_totalUserButton.addActionListener(event);
		
		m_backButton = new ImageButton("image/backButton.jpg", "한수 물리기", "image/backButtonOver.jpg");
		m_backButton.addActionListener(event);
		
		m_rightPanel.add(m_backButton);
		m_backButton.setBounds(73,544,65,44);
		
		m_rightPanel.add(m_gamerCaptin);
		m_gamerCaptin.setBounds(2,75,100,130);
//		m_gamerCaptin.setIcon(new ImageIcon(StoneFactory.getInstance().getStone(0)));
		
		m_rightPanel.add(m_gamerCrhallenger);
		m_gamerCrhallenger.setBounds(112,75,100,130);
//		m_gamerCrhallenger.setIcon(new ImageIcon(StoneFactory.getInstance().getStone(1)));
		
		m_rightPanel.add(m_exitButton);
		m_exitButton.setBounds(142, 544, 65, 44);
		m_exitButton.addActionListener(event);
		
		m_rightPanel.setLayout(null);
//		m_rightPanel.setBorder(new TitledBorder("sdf"));
		
		add(m_rightPanel);
		m_rightPanel.setBounds(615,5,210,600);
	}

	public void setTextToLogWindow(String str) {
		m_log.append(str);
	}

	public void setUserList(Vector<String> userList) {
		Vector<String> temp = new Vector<String>();
		
		setRoomKing(userList.get(0));

		if(userList.size() < 2)
			setCrhallenger("Pleas wait....");
		else
			setCrhallenger(userList.get(1));
		
		int i = 0;
		for (String user : userList)
			if (i++ > 1) temp.add(user);
		
//		m_userList.setListData(temp);

	}

	private void setCrhallenger(String user) {
		m_gamerCrhallenger.setText(user);
		this.repaint();
	}

	private void setRoomKing(String user) {
		m_gamerCaptin.setText(user);
		this.repaint();
	}

	public void showMessageBox(String sender, String message, boolean option) {
		new SlipFrame(sender, message, false);
	}

	public JList getJList() {
		return m_userList;
	}

	public void unShow() {
		this.setVisible(false);
	}

	public String getInputText() {
		return m_input.getText();
	}


	public void setTextToInput(String string) {
		m_input.setText(string);
	}

	public void setRoomList(Vector<String> roomList) {
	}	
	
	
	
	
	public static void main(String[] args) {
		JFrame frame = new JFrame("Network FIve Eyes Ver. 1.0");
		Container cp = frame.getContentPane();
		cp.add(new GameRoomGui(null));
		
		frame.setSize(850, 650);
		frame.setVisible(true);
		
		frame.addWindowListener(new WindowAdapter() {
			public void windowClosing(WindowEvent e) {
				System.exit(0);
			}
		});
		System.out.println("Exit");
	}

	
	
	
	/* ========================================================
	 * Canvas __ GameBoard!
	 */

	class GameBoardCanvas extends Canvas {

		/*
		 * Image Size is 590,593
		 */

		private static final long serialVersionUID = 1L;

		private ArrayList<StoneHistory> historyOfStone = new ArrayList<StoneHistory>();

		private Toolkit toolkit = Toolkit.getDefaultToolkit();

		private MediaTracker tracker;

		private Image image, lastStone;

		private BufferedImage bi;

		private int width, height;

		private int[] points;
		
		private int[] lastPoint = new int[2];

		private StoneHistory aStoneInfo;

		private boolean isRedraw = false;
		
		private int whatStone = 0;

		public GameBoardCanvas() {
			imageLoad();
			traker();

			/*
			 * Mouse Click! Event catch!!
			 * 
			 */
			addMouseListener(new MouseAdapter() {
				public void mouseClicked(MouseEvent e) {
					int[] point = new int[2];
					
					if ((16 < e.getX() && e.getX() < 555) && 20 < e.getY()
							&& e.getY() < 560) {

						System.out.println("mouse click!");
						point = FindCrossPoint.find(e.getX(), e.getY());
						
						if(!isStoneDraw(point))
							client.sendMessage(point);
						
//						repaint();
					}
				}
			});
		}
		
		public void addHistory(int[] points, int kindOfStone) {
			aStoneInfo = new StoneHistory(points, StoneFactory.getInstance().getStone(kindOfStone));
			historyOfStone.add(aStoneInfo);
			
			repaint();
		}
		
		// Version 1.01 update
		protected boolean isStoneDraw(int[] points) {

			for (StoneHistory temp : historyOfStone) {
				if(temp.points[0] == points[0] && temp.points[1] == points[1])
					return true;
			}
			return false;
		}
		
		public void subHistory(int count) {
				historyOfStone.remove(historyOfStone.size()-1);

				if (count == 2) subHistory(1);
		}

		public void drawHistory() {
			isRedraw = true;
			repaint();
		}

		public void paint(Graphics g) {
			g.drawImage(bi, 0, 0, this);
//			System.out.println("paint()!");
//			update(g);
		}

		/*
		 * when mouse click, stone is draw.
		 */
		public void update(Graphics g) {

//			System.out.println("update()");

			drawStones(g);
		}


		/*
		 * private Methid~!
		 * 
		 */
		private void drawStones(Graphics g) {
			
			if (!isRedraw) {
				if (lastStone != null) 
					g.drawImage(lastStone, lastPoint[0], lastPoint[1], this);
				
				System.out.println("add()" + historyOfStone);
				lastPoint[0] = aStoneInfo.points[0];
				lastPoint[1] = aStoneInfo.points[1];
				lastStone = aStoneInfo.getStone();
				
				g.drawImage(aStoneInfo.getStone(), lastPoint[0], lastPoint[1], this);

			} else {
				for (StoneHistory temp : historyOfStone) {
					g.drawImage(temp.getStone(), temp.points[0], temp.points[1], this);
					lastPoint[0] = temp.points[0];
					lastPoint[1] = temp.points[1];
				}
				
				isRedraw = false;
			}

			if (lastStone != null) {
				g.setColor(Color.RED);
				g.fillRect(lastPoint[0]+8, lastPoint[1]+8, 7,7);
			}
		}
		
		private StoneHistory getLastStone() {
			return historyOfStone.get(historyOfStone.size() - 1);
		}

		private void traker() {
			try {
				tracker = new MediaTracker(this);
				tracker.addImage(image, 0);
				tracker.waitForID(0);
				width = image.getWidth(null);
				height = image.getHeight(null);
				bi = new BufferedImage(width, height,
						BufferedImage.TYPE_INT_RGB);
				Graphics gg = bi.getGraphics();
				gg.drawImage(image, 0, 0, this);
				gg.dispose();
				repaint();
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
		}
		
		private void imageLoad() {
			image = toolkit.createImage(URLGetter.getResource("image/badook_board.jpg"));
		}

		public void removeStones() {
			historyOfStone = new ArrayList<StoneHistory>();
		}
	}


	
	/*
	 *   Class Of a Stone
	 * 
	 */
	private class StoneHistory {
		int[] points = new int[2];

		Image stone;

		public StoneHistory(int[] points, Image stone) {
			this.points = points;
			this.stone = stone;
		}

		public Image getStone() {
			return this.stone;
		}

		public String toString() {
			return "" + points[0] + " " + points[1];
		}
	}




	public void drawStone(int[] stoneLocation, boolean isBlack) {
		if (isBlack)
			m_board.addHistory(stoneLocation, BLACK_STONE);
		else m_board.addHistory(stoneLocation, WHITE_STONE);
		
	}

	public void setTotalUser(Vector<String> userList) {
		userListFrame.setUserList(userList);
	}

	public void setUserListFrame(UserListFrame userListFrame) {
		this.userListFrame = userListFrame;
	}

	public void backOneStep(int n) {
		m_board.subHistory(n);
		
		m_board.setVisible(false);
		m_board.setVisible(true);
		
		m_board.drawHistory();
	}

	public void setGameRoomInfo(String info) {
		StringTokenizer token = new StringTokenizer(info, "|");
		
		m_titleLabel.setText(token.nextToken());
		m_gamer1.setText(token.nextToken());
		m_gamer2.setText(token.nextToken());
	}

	public void newGame() {
		m_board.removeStones();
		m_board.lastStone = null;
		m_board.lastPoint = new int[2];

		m_board.setVisible(false);
		m_board.setVisible(true);
	}

	public int[] getFrameSize() {
		int[] size = {850, 650};
		return size;
	}
	public void setPanel(PanelInterface panel) {
	}
	public void setPanel(GameLobbyInter panel) {
	}
	public void setPanel(LobbyGuiInter panel) {
	}
	public void setPanel(RoomGuiInter panel) {
	}

	public GameBoardCanvas getM_board() {
		return m_board;
	}
} public interface GuiInterface {
	public void setTextToLogWindow(String str);
	public void setUserList(Vector<String> userList);
	public void showMessageBox(String sender, String message, boolean option);
	public JList getJList();
	public void unShow();
	public String getInputText();
	public void setTextToInput(String string);
	public void setTotalUser(Vector<String> userList);
	public void setUserListFrame(UserListFrame userListFrame);
	public void setPanel(PanelInterface panel);
	public void setPanel(GameLobbyInter panel);
	public void setPanel(LobbyGuiInter panel);
	public void setPanel(RoomGuiInter panel);
} public class InfoFrame extends JWindow {

	private static final long serialVersionUID = 1L;
	
	private Container cp = getContentPane();
	private JTextArea m_message = new JTextArea();
	
	public InfoFrame(String message) {
		cp.add(m_message);
		cp.setLayout(null);
		m_message.setBounds(10,10,180,80);
		m_message.setEditable(false);
		m_message.setLineWrap(true);
		
		m_message.setText(message);
		
		setBounds(200,300,200,100);
		setAlwaysOnTop(true);
	}
	

	
	public static void main(String[] args) {
		new InfoFrame("ASDFSDFasdfasdfas\ndfasdfsdfasdfsSDF").setVisible(true);
	}
} @SuppressWarnings("serial")
public class LobbyGui extends JPanel implements LobbyGuiInter, PanelInterface{

	private ClientInterface client;
	
	private EventExecute event;
	
	private UserListFrame userListFrame;

	/*
	 * Component of Room List Panel
	 */
	private JPanel m_roomListPanel = new JPanel() {
		public void paint(Graphics g) {
			this.paintComponents(g);
		}
	};

	private JList m_roomList = new JList();
	
	private JTable m_roomListTable;

	private JScrollPane m_scPaneRoomList;

	private ImageButton m_createRoomButton, m_enterRoomButton;

	/*
	 * Component of User List Panel
	 */
	private JPanel m_userListPanel = new JPanel() {
		public void paint(Graphics g) {
			this.paintComponents(g);
		}
	};
	private JList m_userList = new JList();
	private JPopupMenu popup;
	private JScrollPane m_scPaneUserList;
	private ImageButton m_totalUserButton;

	/*
	 * Component of Chat Window
	 */
	private JPanel m_logWinPanel = new JPanel() {
		public void paint(Graphics g) {
			this.paintComponents(g);
		}
	};

	private JTextArea m_logWindow = new JTextArea(5, 20);

	protected JTextField m_textInput = new JTextField();

	private ImageButton m_sendButton = new ImageButton("image/lobbySendButton.jpg", "SEND","image/lobbySendButtonOver.jpg");

	private JScrollPane m_scPaneLogWin;
	
	private JScrollBar m_vScroll;

	/*
	 * Component of Info Panel
	 */
	private JPanel m_infoPanel = new JPanel() {
		public void paint(Graphics g) {
			this.paintComponents(g);
		}
	};

	private JLabel m_infoLabel = new JLabel();

	private ImageButton m_exitButton = new ImageButton("image/lobbyExitButton.jpg", "EXIT","image/lobbyExitButtonOver.jpg");

	/*
	 * 임시...
	 */
	private Vector<String> vc = new Vector<String>(1);

	
	/*
	 * 생성자.
	 */
	public LobbyGui(ClientInterface client) {
		this.client = client;
		event = new EventExecute(this, client);
		
		vc.add("");
		excute();
	}
	
	public void paint(Graphics g) {
		ImageIcon icon = new ImageIcon(
				URLGetter.getResource("image/lobbyBg.jpg"));
		g.drawImage(icon.getImage(),0,0,null,null);
		this.paintComponents(g);
	}

	public static void main(String[] args) {
		JFrame frame = new JFrame("Network FIve Eyes Ver. 1.0");
		Container cp = frame.getContentPane();
		cp.add(new LobbyGui(null));
		
		frame.setSize(340,440);
		frame.setVisible(true);
		
		frame.addWindowListener(new WindowAdapter() {
			public void windowClosing(WindowEvent e) {
				System.exit(0);
			}
		});
		System.out.println("Exit");
	}

	private void excute() {
		add(generatorRoomListPanel());
		add(generatorUserListPanel());
		add(generatorChatWindowPanel());
		add(generatorInfoPanel());
		setLayout(null);
	}
	
	private JPanel generatorRoomListPanel() {
		m_createRoomButton = new ImageButton("image/makeRoomButton.jpg", "Create Game Room","image/makeRoomButtonOver.jpg");
		m_enterRoomButton = new ImageButton("image/enterRoomButton.jpg", "Enter Game Room","image/enterRoomButtonOver.jpg");

		m_roomList.setListData(vc);

		m_scPaneRoomList = new JScrollPane(m_roomList,
				JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
				JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
		
//		m_scPaneRoomList.setBorder(new TitledBorder("Game Room List"));
		m_scPaneRoomList.setBounds(5,5,150,100);

		m_roomListPanel.add(m_createRoomButton);
		m_createRoomButton.setBounds(10, 110, 65, 44);
		m_roomListPanel.add(m_enterRoomButton);
		m_enterRoomButton.setBounds(85, 110, 65, 44);

		m_roomListPanel.add(m_scPaneRoomList);
		m_roomListPanel.setLayout(null);
		m_roomListPanel.setBounds(5,25,160,160);
		
//		m_roomListPanel.setBorder(new TitledBorder("SDfsd"));
		
		m_createRoomButton.addActionListener(event);
		m_enterRoomButton.addActionListener(event);

		return m_roomListPanel;
	}

	private JPanel generatorUserListPanel() {
		m_userList.setListData(vc);

		m_scPaneUserList = new JScrollPane(m_userList,
				JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
				JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
//		m_scPaneUserList.setBorder(new TitledBorder("User List"));
		m_scPaneUserList.setBounds(5, 5, 150, 100);
		
		m_totalUserButton = new ImageButton("image/lobbyTotalUserButton.jpg", "Total User","image/lobbyTotalUserButtonOver.jpg");
		m_userListPanel.add(m_totalUserButton);
		m_totalUserButton.setBounds(5,110,150,44);
		m_totalUserButton.addActionListener(event);
		
		m_userListPanel.add(m_scPaneUserList);
		m_userListPanel.setLayout(null);
		m_userListPanel.setBounds(165, 25, 200,160);
		
//		m_userListPanel.setBorder(new TitledBorder("SDfsd"));		
		m_userList.addMouseListener(new MouseAdapter() {
			public void mouseClicked(MouseEvent e) {
				showPopupMenu(e);
			}
		});
		
		return m_userListPanel;
	}
	
	private void showPopupMenu(MouseEvent e) {
		JMenuItem menuSendSlip = new JMenuItem("쪽지 보내기");
		menuSendSlip.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				new SlipFrame((String) m_userList.getSelectedValue(), null, true, client);
			}
		});

		popup = new JPopupMenu();
		popup.add(menuSendSlip);
		popup.show(m_userList, e.getX(), e.getY());
	}
	

	private JPanel generatorChatWindowPanel() {
		m_scPaneLogWin = new JScrollPane(m_logWindow,
				JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
				JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
//		m_scPaneLogWin.setBorder(new TitledBorder("Chatting Window"));
		m_logWindow.setEditable(false);
		m_logWindow.setLineWrap(true);
		m_scPaneLogWin.setBounds(5,5,310,150);
		m_vScroll = m_scPaneLogWin.getVerticalScrollBar();
		m_vScroll.addAdjustmentListener(new AdjustmentListener() {
			public void adjustmentValueChanged(AdjustmentEvent e) {
//				System.out.println("************** EVENT!!!" + e.getValueIsAdjusting());
				if(!e.getValueIsAdjusting()) m_vScroll.setValue(m_vScroll.getMaximum());
//				m_vScroll.removeAdjustmentListener(this);
				
			}
		});
		
		
		m_logWinPanel.add(m_textInput);
		m_textInput.setBounds(5, 160, 170, 30);
		m_logWinPanel.add(m_sendButton);
		m_sendButton.setBounds(180, 160, 65, 30);
		m_logWinPanel.add(m_exitButton);
		m_exitButton.setBounds(250,160,65,30);

		m_logWinPanel.add(m_scPaneLogWin);
		m_logWinPanel.setLayout(null);
		m_logWinPanel.setBounds(5, 205, 320, 200);
		
		
//		m_logWinPanel.setBorder(new TitledBorder("SDfsd"));
		
		m_textInput.setName("input");
		m_textInput.addActionListener(event);
		m_sendButton.addActionListener(event);
		
		return m_logWinPanel;
	}

	private JPanel generatorInfoPanel() {
		m_infoPanel.add(m_infoLabel);
		m_infoLabel.setBounds(5,5,190,100);
		
		
		
		m_infoPanel.setLayout(null);
		m_infoPanel.setBounds(330, 205, 200,200);

//		m_infoPanel.setBorder(new TitledBorder("SDfsd"));
		
		m_exitButton.addActionListener(event);
		
		return m_infoPanel;
	}

	
	/*
	 * public mothod! interface implements.....
	 */
	public void setTextToLogWindow(String str) {
		m_logWindow.append(str);
	}

	public void setUserList(Vector<String> UserList) {
		m_userList.setListData(UserList);
	}

	public void showMessageBox(String sender, String message, boolean option) {
		new SlipFrame(sender, message, false);
	}

	public JList getUserList() {
		return m_userList;
	}

	public JList getJList() {
		return m_userList;
	}
	

	public void unShow() {
		this.setVisible(false);
	}


	public String getInputText() {
		return m_textInput.getText();
	}


	public void setTextToInput(String string) {
		m_textInput.setText(string);
	}


	public void setRoomList(Vector<String> roomList) {
		m_roomList.setListData(roomList);
	}


	public String getSelectRoom() {
		String temp = (String)m_roomList.getSelectedValue();
		return temp;
	}

	public void setTotalUser(Vector<String> userList) {
		userListFrame.setUserList(userList);
	}


	public void setUserListFrame(UserListFrame userListFrame) {
		this.userListFrame = userListFrame;
	}


	public void setPanel(PanelInterface panel) {
		// TODO Auto-generated method stub
		
	}


	public int[] getFrameSize() {
		int[] size = {340,440};
		return size;
	}

	public void setPanel(GameLobbyInter panel) {
	}
	public void setPanel(LobbyGuiInter panel) {
	}
	public void setPanel(RoomGuiInter panel) {
	}
} public interface LobbyGuiInter extends GuiInterface {

	void setRoomList(Vector<String> roomList);

	String getSelectRoom();
	int[] getFrameSize();
} @SuppressWarnings("serial")
public class LoginPanel extends JPanel implements PanelInterface {
	
	private ClientLobby client;

	private JTextField inputId;
	private JPasswordField inputPass;
	private ImageButton loginButton;
	
	@SuppressWarnings("serial")
	public LoginPanel(final ClientLobby client) {
		this.client = client;
		
		inputId = new JTextField(7);
		inputPass = new JPasswordField(7);
		loginButton = new ImageButton("image/loginButton.jpg", "LOGIN","image/loginButtonOver.jpg");
		
		add(inputId);
		add(inputPass);
		add(loginButton);
		
		inputId.setBounds(130,175,100,25);
		inputPass.setBounds(130,205,100,25);
		loginButton.setLocation(255, 165);
		
		inputId.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				if(!inputId.getText().equals("")) {
					client.setName(inputId.getText());
					client.changePanel(new LobbyGui(client));
				}
			}
		});
		
		inputPass.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				if(!inputId.getText().equals("")) {
					client.setName(inputId.getText());
					client.changePanel(new LobbyGui(client));
				}
			}
		});
		
		loginButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				if(!inputId.getText().equals("")) {
					client.setName(inputId.getText());
					client.changePanel(new LobbyGui(client));
				}
			}
		});
		
		setLayout(null);
	}
	
	public void paint(Graphics g) {
		ImageIcon icon = new ImageIcon(
				URLGetter.getResource("image/loginForm.jpg"));
		g.drawImage(icon.getImage(),0,0,null,null);
		this.paintComponents(g);
	}
	
	public int[] getFrameSize() {
		int size[] = new int[2];
		size[0] = 405;
		size[1] = 325;
		return size;
	}
	
	public static void main(String[] args) {
		new LoginForm();
	}
	
	

	public String getInputText() {
		return null;
	}

	public JList getJList() {
		return null;
	}

	public void setTextToInput(String string) {
	}
	public void setTextToLogWindow(String str) {
	}
	public void setTotalUser(Vector<String> userList) {
	}
	public void setUserList(Vector<String> userList) {
	}
	public void setUserListFrame(UserListFrame userListFrame) {
	}
	public void showMessageBox(String sender, String message, boolean option) {
	}
	public void unShow() {
	}
	public void setPanel(PanelInterface panel) {
	}
	public void setPanel(GameLobbyInter panel) {
	}
	public void setPanel(LobbyGuiInter panel) {
	}
	public void setPanel(RoomGuiInter panel) {
	}
} @SuppressWarnings("serial")
public class MainFrame extends JFrame implements GuiInterface, LobbyGuiInter, GameLobbyInter, RoomGuiInter {

	private Container cp = this.getContentPane();
	private PanelInterface panel;
	private GameLobbyInter panelGameLobby;
	private LobbyGuiInter panelLobby;
	private RoomGuiInter panelRoom;
	private GuiInterface gui;
	
	public MainFrame(final ClientLobby client) {
		super("Network Omok Ver. 1.0");
		addWindowListener(new WindowAdapter() {
			public void windowClosing(WindowEvent e) {
				client.sendMessage("´ÔÀÌ ³ª°¡¼Ì½À´Ï´Ù.",  ChatData.EXIT);
				System.exit(0);
			}
		});
		
//		 when Window is Actvate, this Event call.
		addWindowListener(new WindowAdapter() {
			public void windowActivated(WindowEvent e) {
				if(panelRoom != null)
					panelRoom.getM_board().drawHistory();
			}
		});
	}
	
	public String getInputText() {
		return gui.getInputText();
	}

	public JList getJList() {
		return gui.getJList();
	}

	public void setTextToInput(String string) {
		gui.setTextToInput(string);
	}

	public void setTextToLogWindow(String str) {
		gui.setTextToLogWindow(str);
	}

	public void setTotalUser(Vector<String> userList) {
		gui.setTotalUser(userList);
	}

	public void setUserList(Vector<String> userList) {
		gui.setUserList(userList);
	}

	public void setUserListFrame(UserListFrame userListFrame) {
		gui.setUserListFrame(userListFrame);
	}

	public void showMessageBox(String sender, String message, boolean option) {
		gui.showMessageBox(sender, message, option);
	}

	public void unShow() {
		gui.unShow();
	}

	public void setPanel(GameLobbyInter panel) {
		System.out.println("################### gameLobby in");
		cp.removeAll();
		
		this.panelGameLobby = panel;
		this.gui = panel;
		cp.add((Component) panel);
		
		int[] size = panelGameLobby.getFrameSize();
		
		this.setSize(size[0], size[1]);
		this.setVisible(true);
		System.out.println("################### gameLobby out");
	}
	
	public void setPanel(PanelInterface panel) {
		cp.removeAll();
		
		this.panel = panel;
		this.gui = panel;
		cp.add((Component) panel);
		
		int[] size = panel.getFrameSize();
		
		this.setSize(size[0], size[1]);
		this.setVisible(true);
	}
	
	public void setPanel(LobbyGuiInter panel) {
		cp.removeAll();
		
		this.panelLobby = panel;
		this.gui = panel;
		cp.add((Component) panelLobby);
		
		int[] size = panelLobby.getFrameSize();
		
		this.setSize(size[0], size[1]);
		this.setVisible(true);
	}
	
	public void setPanel(RoomGuiInter panel) {
		cp.removeAll();
		
		this.panelRoom = panel;
		this.gui = panel;
		cp.add((Component) panel);
		
		int[] size = panelRoom.getFrameSize();
		
		this.setSize(size[0], size[1]);
		this.setVisible(true);
	}

	public String getSelectRoom() {
		return panelLobby.getSelectRoom();
	}

	public void setRoomList(Vector<String> roomList) {
		panelLobby.setRoomList(roomList);
	}

	public String getGameInfo() {
		return panelGameLobby.getGameInfo();
	}

	public void setButtonEnable(boolean clickable) {
		panelGameLobby.setButtonEnable(clickable);
	}

	public void setCrhallenger(String string) {
		panelGameLobby.setCrhallenger(string);
	}

	public void setGameRoomInf(String info) {
		panelGameLobby.setGameRoomInf(info);
	}

	public void setRoomKing(String name) {
		panelGameLobby.setRoomKing(name);
	}

	public void setStartButton(boolean isRoomKing) {
		panelGameLobby.setStartButton(isRoomKing);
	}

	public void backOneStep(int n) {
		panelRoom.backOneStep(n);
	}

	public void drawStone(int[] stoneLocation, boolean b) {
		panelRoom.drawStone(stoneLocation, b);
	}

	public void newGame() {
		panelRoom.newGame();
	}

	public void setGameRoomInfo(String info) {
		panelRoom.setGameRoomInfo(info);
	}

	public int[] getFrameSize() {
		return null;
	}

	public GameBoardCanvas getM_board() {
		return panelRoom.getM_board();
	}
} public interface PanelInterface extends GuiInterface {
	public void setTextToLogWindow(String str);
	public void setUserList(Vector<String> userList);
	public void showMessageBox(String sender, String message, boolean option);
	public JList getJList();
	public void unShow();
	public String getInputText();
	public void setTextToInput(String string);
	public void setTotalUser(Vector<String> userList);
	public void setUserListFrame(UserListFrame userListFrame);
	public int[] getFrameSize();
} public interface RoomGuiInter extends PanelInterface {
	int BLACK_STONE = 0;
	int WHITE_STONE = 1;
	
	void drawStone(int[] stoneLocation, boolean b);
	void backOneStep(int n);
	void setGameRoomInfo(String info);
	void newGame();
	void setRoomList(Vector<String> roomList);
	GameBoardCanvas getM_board();
}
import gui.GameLobby;
import gui.GameLobbyInter;
import gui.GameRoomGui;
import gui.GuiInterface;
import gui.InfoFrame;
import gui.LobbyGui;
import gui.LobbyGuiInter;
import gui.LoginPanel;
import gui.MainFrame;
import gui.PanelInterface;
import gui.RoomGuiInter;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.net.InetSocketAddress;
import java.net.Socket;
import java.net.SocketAddress;
import java.util.Vector;
import javax.swing.JOptionPane;
import protocolData.*;
		case ChatData.SEND_USER_LIST:
			System.out.println("in send user list");
			m_Frame.setUserList(data.getUserList());
			break;

		case ChatData.SEND_TOTAL_USER:
			m_Frame.setTotalUser(data.getUserList());
			break;

		default:
			setTextToLog(data);
			break;
		}
	}

	private void analysisLobbyData(LobbyData data) {
		switch (data.getProtocol()) {

		case LobbyData.CREATE_ROOM:
			/*
			 * create Room...
			 */
			setRoomKing(true);
			
			changePanel(new GameLobby(this, true));
			setGameLobbyInstance();
			m_gameLobby.setRoomKing(name);

			m_gameLobby.setStartButton(true);

			m_gameLobby.setGameRoomInf("[" + data.getRoomNumber() + "번방] "
					+ data.getRoomName());

			break;

		case LobbyData.ENTER_TO_ROOM:
			changePanel(new GameLobby(this,false));
			setGameLobbyInstance();
			m_gameLobby.setCrhallenger(this.name);

			m_gameLobby.setStartButton(false);

			Vector<String> temp = new Vector<String>();

			for (String user : data.getUserList())
				temp.add(user);

			m_gameLobby.setUserList(temp);

			m_gameLobby.setGameRoomInf("[" + data.getRoomNumber() + "번방] "
					+ data.getRoomName());
			
			showEnterMessage(data);
			
			break;

		case LobbyData.SEND_ROOMLIST:
			/*
			 * send Room LIst...
			 */
			((RoomGuiInter) m_Frame).setRoomList(data.getRoomList());

			break;

		case LobbyData.EXIT_GAME:
			/*
			 * when Room king exit this room.
			 */
			break;

		default:
			break;
		}

	}

	private void showEnterMessage(Protocol data) {
		m_Frame.setTextToLogWindow("[ " + data.getName() + " ] 님이 입장하셨습니다 \n");
	}

	private void showExitMessage(Protocol data) {
		m_Frame.setTextToLogWindow("[ " + data.getName() + " ] 님이 나가셨습니다 \n");
	}

	private void analysisGameLobbyData(GameLobbyData data) {
		switch (data.getProtocol()) {

		case GameLobbyData.CANCEL_READY:
			/*
			 * ready is canceled...
			 */
			m_gameLobby.setButtonEnable(false);

			break;

		case GameLobbyData.EXIT_ROOM:
			/*
			 * exit the room...
			 */
			JOptionPane.showConfirmDialog(null, "Room Master exit this room!",
					"Notice!", JOptionPane.DEFAULT_OPTION);

			isInRoom = false;
			changePanel(new LobbyGui(this));
			setLobbyInstance();

			break;

		case GameLobbyData.GAME_READY:
			/*
			 * All gamer is ready... (only roomking execute...)
			 */
			m_gameLobby.setButtonEnable(true);

			break;

		case GameLobbyData.GAME_START:
			/*
			 * game start!!
			 */
			changePanel(new GameRoomGui(this));