Example #1
0
  @Override
  public void update(Observable arg0, Object arg1) {
    if (arg1 instanceof String) {
      String message = arg1.toString();
      if (message.startsWith("Forwarding: ")) {
        ForwardButton.setText("Stop Forwarding");
        SetChannelButton.setEnabled(false);
        BlockButton.setEnabled(false);
        Send.setEnabled(false);
        MessageInput.setEnabled(false);
        MessageDisplay.setEnabled(false);
        Availability.setEnabled(false);
      } else if (message.startsWith("End Forwarding:")) {
        ForwardButton.setText("Forward");
        SetChannelButton.setEnabled(true);
        BlockButton.setEnabled(true);
        Send.setEnabled(true);
        MessageInput.setEnabled(true);
        MessageDisplay.setEnabled(true);
        Availability.setEnabled(true);
      } else if (message.startsWith("#send")) {
        try {
          client.sendToServer(message.substring(6));
        } catch (IOException e) {
          e.printStackTrace();
        }
        return;
      } else if (message.startsWith("#linedraw")) {
        drawPad.updateDraw(message);
        return;
      } else if (message.startsWith("Login Error:")) {
        java.awt.EventQueue.invokeLater(
            new Runnable() {
              public void run() {
                chatFrame.setVisible(false);
                LoginGUI login = new LoginGUI(true);
              }
            });
      }

      if (!message.substring(message.length() - 1, message.length()).equals("\n")) message += "\n";

      // Update UI display safely
      final String msg = message;
      SwingUtilities.invokeLater(
          new Runnable() {
            public void run() {
              MessageDisplay.append(msg);
            }
          });
    }
  }
Example #2
0
  /** Creates new form GUI */
  public ClientGUI(String loginID, String password, String host, int port) {
    try {
      client = new ChatClient(loginID, password, host, port, this);
    } catch (IOException exception) {
      System.out.println("Cannot open connection. Awaiting command.");
      // System.exit(1);
    }

    try {
      client.addObserver(this);
    } catch (Exception e) {
      // server not started
      JOptionPane.showMessageDialog(
          null, "Error: Could not connect to server.  Make sure server is started and try again");
      System.exit(0);
    }
    SetupUI(loginID);
    self = this;
  }
Example #3
0
 public static void main(String[] args) {
   ChatClient auxChat = new ChatClient();
   auxChat.launchFrame();
 }
Example #4
0
 public static void main(String[] args) {
   ChatClient window = new ChatClient();
   window.setSize(800, 600);
   window.setVisible(true);
 }