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

43
LINES

< > BotCompany Repo | #1009798 // Swing: Send message to bot [OK]

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

Download Jar. Uses 3874K of libraries. Click here for Pure Java version (6440L/45K).

!7

p-noconsole {
  final JComboBox cbBot = currentBotsComboBox();
  final JTextField tfMsg = jtextfield();
  final JTextField tfResult = standardTextFieldPopupMenu(juneditabletextfield());
  final JLabel lblTiming = jrightalignedlabel();
  final JLabel lblBot = jlabel();
  final JLabel lblMessageSent = jlabel();
  
  setFrameWidth(800, showFormTitled("Send message to bot",
    jrightalignedlabel("Bot"), botSelector_withRefresh(cbBot),
    jrightalignedlabel("Message"), tfMsg,
    
    "", lblMessageSent,
    "", lblBot,
    jrightalignedlabel("Result"), tfResult,
    "", lblTiming,
    "", jbutton("Send", r {
      S bot = getText(cbBot);
      print("Bot: " + bot);
      fS address = botSelector_getAddress(cbBot);
      print("Address: " + bot);
      if (empty(address)) ret;
      fS msg = getText(tfMsg);
      setText(lblMessageSent, "Sent message: " + msg);
      setText(lblBot, "To bot: " + bot);
      setText(tfResult, "Sending...");
      thread "Send" {
        long time = sysNow();
        try {
          S answer = send(address, msg);
          S a = shorten(answer, 10000);
          setText(tfResult, eq(answer, a) ? answer : "(shortened) " + a);
        } catch e {
          setText(tfResult, "(Error) " + getInnerMessage(e));
        }
        setText(lblTiming, (sysNow()-time) + " ms"); 
      }
    })));
    
  //swing { addActionListener(cbBot, r { print("sel=" + cbBot.getSelectedItem()) }); }
}

download  show line numbers  debug dex  old transpilations   

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

No comments. add comment

-
Snippet ID: #1009798
Snippet name: Swing: Send message to bot [OK]
Eternal ID of this version: #1009798/28
Text MD5: 2639e4d970b79ad1450e6a3c0854ea4b
Transpilation MD5: 2f4f099f835a636267ce5219ef22b85c
Author: stefan
Category: javax / talking robots / gui
Type: JavaX source code (desktop)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2017-08-26 20:32:56
Source code size: 1475 bytes / 43 lines
Pitched / IR pitched: No / No
Views / Downloads: 630 / 1423
Version history: 27 change(s)
Referenced in: