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

41
LINES

< > BotCompany Repo | #1020045 // Ask Me A Question [Computer asks, human answers, dev.]

JavaX source code (Dynamic Module) [tags: use-pretranspiled] - run with: Stefan's OS

Uses 911K of libraries. Click here for Pure Java version (9223L/49K).

1  
!7
2  
3  
cmodule AskMeAQuestion {
4  
  S question, answer;
5  
  
6  
  visualize {
7  
    if (empty(question)) newQuestion();
8  
    JLabel lblQ = dm_fieldLabel('question);
9  
    componentPopupMenuItem(lblQ, "Suggest question...", r {
10  
      inputText("Question", question, voidfunc(S s) {
11  
        setField(question := s)
12  
      })
13  
    });
14  
    ret withRightMargin(makeForm2(
15  
      "Computer question", lblQ,
16  
      "Human answer", centerAndEastWithMargin(onEnter(dm_fieldTextField('answer), rThread submit),
17  
        jbutton("Submit", rThread submit)),
18  
      "", withTopMargin(15, rightAlignedButtons("Ask me something else", rThread newQuestion))));
19  
  }
20  
  
21  
  S randomWord() {
22  
    ret randomEnglishWordFromDictionary();
23  
  }
24  
  
25  
  S makeQuestion() {
26  
    ret "Is " + randomWord() + " the same as " + randomWord() + "?";
27  
  }
28  
  
29  
  void newQuestion enter {
30  
    setFields(answer := "", question := makeQuestion());
31  
    programLogStructure(litorderedmap(+question));
32  
    vmBus_send('showingQuestion, module(), question);
33  
  }
34  
  
35  
  void submit enter {
36  
    programLogStructure(litorderedmap(+question, +answer));
37  
    vmBus_send('userAnsweredQuestion, module(), question, answer);
38  
    dm_addQAndA_infoBox(question, answer);
39  
    newQuestion();
40  
  }
41  
}

download  show line numbers  debug dex  old transpilations   

Travelled to 8 computer(s): bhatertpkbcr, cfunsshuasjs, gwrvuhgaqvyk, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1020045
Snippet name: Ask Me A Question [Computer asks, human answers, dev.]
Eternal ID of this version: #1020045/13
Text MD5: 7550b46fcf9a40d2561850610bc57442
Transpilation MD5: 21577b2a738ce6818faf462cbd5b376e
Author: stefan
Category: javax / a.i.
Type: JavaX source code (Dynamic Module)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2019-01-23 17:17:36
Source code size: 1249 bytes / 41 lines
Pitched / IR pitched: No / No
Views / Downloads: 367 / 1532
Version history: 12 change(s)
Referenced in: [show references]