Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

91
LINES

< > BotCompany Repo | #1001787 // Quick Talk Window 2

JavaX source code [tags: use-pretranspiled] - run with: x30.jar

Libraryless. Click here for Pure Java version (2713L/18K/62K).

!747
!awt {
!named thread

m {
  static JLabel botName;
  static JTextField tfDest, tfInput, tfOutput;
  static JCheckBox cbSign;
  static S currentPort;

  p {
    makeAndroid3("Quick Talk Window 2.");
    
    showFrame("Quick Talk", stack(
      "Destination (bot name/address):",
      tfDest = new JTextField("remote"),
      "Bot name:",
      botName = new JLabel("(filled in later)"),
      cbSign = new JCheckBox("Sign"),
      "Your input (Enter to send):",
      tfInput = new JTextField(),
      "Bot answer:",
      tfOutput = new JTextField()));

    onFocusLeave(tfDest, runnable { inquire(); });      
    onEnter(tfDest, runnable { send(); });
    onEnter(tfInput, runnable { send(); });
  }
  
  static void setBotName(S name) {
    botName.setText(name);
  }
  
  static void inquire() {
    go(false);
  }
  
  static void send() {
    go(true);
  }
  
  static void go(final boolean send) {
    tfOutput.setText("Connecting...");
    thread "sending" {
      try {
        final DialogIO io = findBot(tfDest.getText());
        if (io == null) {
          tfOutput.setText("Bot not found...");
          setBotName("");
          ret;
        }
        try {
          tfOutput.setText("Greeting...");
          
          // get main name
          S name = firstPartOfHelloString(io.readLine());
          // optionally get name of sub-bot
          io.sendLine("your name");
          S line = io.readLine();
          if (!eq(line, "?"))
            name = line;
          setBotName(name);
          
          if (!send) {
            tfOutput.setText("");
            ret;
          }
          
          line = tfInput.getText().trim();
          boolean sign = isChecked(cbSign);
          if (line.startsWith("s/")) {
            line = line.substring(2);
            sign = true;
          }
          if (sign)
            line = format3("signed: *", signWithComputerID(line));
            
          tfOutput.setText("Sending...");
          io.sendLine(line);
          final S output = io.readLine();
          tfOutput.setText(output != null ? output : "?");
        } finally {
          io.close();
        }
      } catch (Throwable e) {
        e.printStackTrace();
        tfOutput.setText(e.toString());
      }
    }
  }
}

Author comment

Began life as a copy of #1001760

download  show line numbers  debug dex  old transpilations   

Travelled to 15 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, onxytkatvevr, pyentgdyhuwx, pzhvpgtvlbxg, teubizvjbppd, tslmcundralx, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1001787
Snippet name: Quick Talk Window 2
Eternal ID of this version: #1001787/1
Text MD5: e41b894b02bc9d42f0a296cf425bc481
Transpilation MD5: 4640dbaea1ce3418e019823959532ef9
Author: stefan
Category: javax
Type: JavaX source code
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2015-11-19 21:14:38
Source code size: 2357 bytes / 91 lines
Pitched / IR pitched: No / Yes
Views / Downloads: 649 / 1078
Referenced in: [show references]