@Override
    public void init(){        
        btnExit = new GameButton("X",GamePanel.WIDTH-60,10);
        addComponent(btnExit);
        btnExit.addButtonListener(new ButtonListener(){          
            public void buttonClicked() {
                client.close();
                client.stop();
               setState(GameStateManager.MULTI_PLAYER_STATE);
            }                
        });
        btnMinimize = new GameButton("_",GamePanel.WIDTH-110,10);
        addComponent(btnMinimize);
        btnMinimize.addButtonListener(new ButtonListener(){          
            public void buttonClicked() {
                GamePanel.parent.setState(JFrame.ICONIFIED);
            }                
        });
        btnReady = new GameButton("Ready!",GamePanel.WIDTH-100,GamePanel.HEIGHT-50);
        btnReady.setFont("Arial", 16);
        addComponent(btnReady);
        btnReady.addButtonListener(new ButtonListener(){
            public void buttonClicked() {
                ReadyState r= new ReadyState();
                r.clientReady=true;
                client.sendTCP(r);
                btnReady.setEnabled(false);
            }
            
        });
        
        chatInput = new TextBox("Enter text here...",10,GamePanel.HEIGHT-300+90);
            chatInput.setFocus(false);
            chatInput.setMultiLine(false);
            chatInput.setWidth(GamePanel.WIDTH-300);
            chatInput.setFont("Arial", 12);
            chatInput.resizeHeight();
            
            chatInput.addKeyListener(new KeyListener(){
                @Override
                public void KeyTyped(int keyCode, char keyChar) {
                    if(keyCode == Keys.VK_ENTER){
                        ChatMessage request = new ChatMessage();
                        String toSend = chatInput.getText().trim();
                        if(toSend.length()==0)return;
                        request.text =toSend;
                        client.sendTCP(request);
                        chatInput.setText("");
                    }
                }
            });
            chatInput.addMouseListener(new ButtonListener(){
                @Override
                public void buttonClicked() {
                    if(firstClick){
                        firstClick = false;
                        chatInput.setText("");
                    }
                }
            });
            
            chatLog= new TextBox(10,85,GamePanel.WIDTH-300,GamePanel.HEIGHT-300);
            chatLog.setFont("Arial", 12);
            chatLog.setEditable(false);
            chatLog.setMultiLine(true);
            chatLog.setText("WELCOME TO 4 P O N G chat lobby:\n");
            
            addComponent(chatInput);
            addComponent(chatLog);
            
            //Network code
            users = new String[0];
            client = new Client();
            Network.register(client);

            new Thread(client).start();
            
            
            client.addListener(new Listener(){
                public void connected(Connection c)
                {
                    chatLog.appendText("Connected to Chat!\n");
                    RegisterName registerName = new RegisterName();
                    registerName.name = userName;
                    client.sendTCP(registerName);
                }
                public void received(Connection connection, Object object){
                    
                    if(object instanceof ChatMessage)
                    {
                        ChatMessage response = (ChatMessage)object;
                        chatLog.appendText(response.text+"\n");
                    }
                    if(object instanceof RegisteredNames)
                    {
                        RegisteredNames names = (RegisteredNames)object;
                        users = names.names;
                        ready = names.ready;                        
                    }
                    if(object instanceof BeginGame)
                    {
                        client.close();
                        client.stop();
                        setState(GameStateManager.MULTI_PLAYER_GAME_STATE);
                    }
                }
                public void disconnected(Connection c)
                {
                    setState(GameStateManager.MULTI_PLAYER_STATE);
                }
            });  
            
            new Thread(){
                public void run(){   
                    try{                                
                        chatLog.appendText("Connecting to server \n");          
                        client.connect(5000, "67.188.28.76", Network.TCPport,Network.UDPport);                        
                    }catch(IOException ex){chatLog.appendText(ex.getMessage());
                        chatLog.appendText("\nConnecting to LAN server \n");                              
                        try{
                            InetAddress addr  = client.discoverHost(Network.UDPport, 10000);
                            client.connect(5000, addr, Network.TCPport,Network.UDPport);
                        }catch(Exception e){chatLog.appendText(e.getMessage());setState(GameStateManager.MULTI_PLAYER_STATE);}
                    }              

                }                
            }.start();
    }