Exemplo n.º 1
0
 void jTextFieldSendMessages_keyPressed(KeyEvent e) {
   if (e.getKeyCode() == e.VK_DOWN) {
     String s = msgHistory.forward();
     if (s != null) {
       jTextFieldSendMessages.setText(s);
     }
   } else if (e.getKeyCode() == e.VK_UP) {
     String s = msgHistory.back();
     if (s != null) {
       jTextFieldSendMessages.setText(s);
     }
   } else if (e.getKeyChar() == '\n') {
     String body = jTextFieldSendMessages.getText();
     if (body.length() > 0) {
       if (body.charAt(body.length() - 1) == '\n') body = body.substring(0, body.length() - 1);
       String subject = jTextFieldSendSubject.getText();
       if (subject.length() > 0) {
         if (subject.charAt(subject.length() - 1) == '\n')
           subject = subject.substring(0, subject.length() - 1);
       }
       if (session != null && session.isConnected()) {
         session.postMessage(jTextFieldTargetUser.getText(), subject, body);
         displaySendMessage(subject, jTextFieldTargetUser.getText(), body, outgoingMsgAttrSet);
       }
       msgHistory.add(body);
       subjectHistory.add(subject);
       subjectHistory.reset();
       msgHistory.reset();
       jTextFieldSendMessages.setText("");
       jTextFieldSendSubject.setText("");
     }
   }
 }
Exemplo n.º 2
0
  void HireFire_actionPerformed(ActionEvent e) {
    applicant selectedEmp; // employee selected by user from jList

    if (!appList.isEmpty()) {
      // Do what you wish the selected applicant
      selectedEmp = (applicant) jList1.getSelectedValue();
      if (selectedEmp.Hired.equals("0"))
        Moo.send("hire " + selectedEmp.ApplicantID + " " + jTextFieldWage.getText());
      else Moo.send("fire");
      Moo.send("get_applicants " + jTextFieldWage.getText()); // refreshes list after changes
    }
  }
Exemplo n.º 3
0
 public void receiveMsg(Message msg) {
   // System.out.println(msg.getSubject() + " : " + msg.getBody());
   String subject = msg.getSubject();
   if (subject != null) {
     if (subject.equals("online")) {
       onlineUsers.addElement(new HostItem(msg.getBody()));
       displayMessage(msg.getBody() + " : Online", onlineClientAttrSet);
     } else if (subject.equals("offline")) {
       onlineUsers.removeElement(new HostItem(msg.getBody()));
       displayMessage(msg.getBody() + " : Offline", offlineClientAttrSet);
     } else if (subject.equals("eavesdrop enabled")) {
       Object[] values = jListOnlineUsers.getSelectedValues();
       if (values == null) return;
       for (int i = 0; i < values.length; i++) {
         ((HostItem) values[i]).eavesDroppingEnabled = true;
       }
       jListOnlineUsers.updateUI();
     } else if (subject.equals("eavesdrop disabled")) {
       Object[] values = jListOnlineUsers.getSelectedValues();
       if (values == null) return;
       for (int i = 0; i < values.length; i++) {
         ((HostItem) values[i]).eavesDroppingEnabled = false;
       }
       jListOnlineUsers.updateUI();
     } else if (subject.equals("globaleavesdrop enabled")) {
       displayMessage("Global Eavesdropping Enabled", onlineClientAttrSet);
     } else if (subject.equals("globaleavesdrop disabled")) {
       displayMessage("Global Eavesdropping Disabled", offlineClientAttrSet);
     } else {
       String to = msg.getTo();
       String from = msg.getFrom() == null ? "server" : msg.getFrom();
       String body = msg.getBody() != null ? msg.getBody() : "";
       if (jTextFieldUser.getText().equals(to)) { // this message is sent to us
         displayMessage(subject, from, body, incomingMsgAttrSet);
       } else { // this is an eavesdrop message
         displayMessage(subject, to, from, body, eavesdropAttrSet);
       }
     }
   } else {
     subject = "";
     String to = msg.getTo();
     String from = msg.getFrom() == null ? "server" : msg.getFrom();
     String body = msg.getBody() != null ? msg.getBody() : "";
     if (jTextFieldUser.getText().equals(to)) { // this message is sent to us
       displayMessage(subject, from, body, incomingMsgAttrSet);
     } else { // this is an eavesdrop message
       displayMessage(subject, to, from, body, eavesdropAttrSet);
     }
   }
 }
Exemplo n.º 4
0
 private void handleConnect() {
   if (jToggleButtonConnect.isSelected() || jMenuItemServerConnect.isEnabled())
     try {
       jTextPaneDisplayMessages.setText("");
       session = new Session();
       try {
         String userid = jTextFieldUser.getText();
         if (jPasswordFieldPwd.getPassword() != null) {
           String pwd = String.valueOf(jPasswordFieldPwd.getPassword()).trim();
           if (!pwd.equals("")) {
             userid += ":" + pwd;
           }
         }
         if (session.connect(jTextFieldServer.getText(), userid)) {
           displayMessage("Connected\n", incomingMsgAttrSet);
           session.addListener(this);
           jToggleButtonConnect.setText("Disconnect");
           jMenuItemServerConnect.setEnabled(false);
           jMenuItemServerDisconnect.setEnabled(true);
         } else {
           jToggleButtonConnect.setSelected(false);
           jMenuItemServerConnect.setEnabled(true);
           jMenuItemServerDisconnect.setEnabled(false);
           displayMessage("Connection attempt failed\n", offlineClientAttrSet);
         }
       } catch (ConnectionException ex1) {
         jToggleButtonConnect.setSelected(false);
         jMenuItemServerConnect.setEnabled(true);
         jMenuItemServerDisconnect.setEnabled(false);
         displayMessage(
             "Connection attempt failed: " + ex1.getMessage() + "\n", offlineClientAttrSet);
       }
     } catch (Exception ex) {
       ex.printStackTrace();
     }
   else {
     disconnect();
     jMenuItemServerConnect.setEnabled(true);
     jMenuItemServerDisconnect.setEnabled(false);
     displayMessage("Disconnected\n", offlineClientAttrSet);
   }
 }
Exemplo n.º 5
0
 void jButtonAdvertise_actionPerformed(ActionEvent e) {
   Moo.send("get_applicants " + jTextFieldWage.getText());
 }