@Override
    /**
     * Start running in the background
     */
    public void run() {
        while (true) {
            try {
                // It'll wait here til we get something.
                Object o = oIn.readObject();
                System.out.println(o);
                if (o instanceof ChatMessage) {
                    System.out.println("changed");
                    this.setChanged();
                    this.notifyObservers(o);
                } else if (o instanceof ChatPerson) {
                    //System.out.println(((ChatPerson)o).getName());
                    this.setChanged();
                    this.notifyObservers(o);
                } else if (o instanceof ServerMessage) {
                    if (((ServerMessage) o).getServerCode() == 1) {
                        this.setChanged();
                        this.notifyObservers(o);
                    }
                }
            } catch (EOFException ex) {
                // Server disconnected. Stop running.
                break;
            } catch (IOException ex) {
                Logger.getLogger(ChatConnection.class.getName()).log(Level.SEVERE, null, ex);
            } catch (ClassNotFoundException ex) {
                Logger.getLogger(ChatConnection.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
        JOptionPane.showMessageDialog(null, "Server connection lost. Closing.");
        System.exit(0);
    }