Skip to content

Commit c21dfe9

Browse files
committed
Пример чата
1 parent 0439b71 commit c21dfe9

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

examples/forms/samobot_chat.own

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
use "std"
2+
use "http"
3+
use "forms"
4+
5+
chatHistory = newLabel("<html>Чат с самоботом<br>")
6+
messageField = newTextField()
7+
sendButton = newButton("Отправить")
8+
9+
messageField.onAction(::onSend)
10+
sendButton.onClick(::onSend)
11+
def onSend() {
12+
text = messageField.getText()
13+
if (length(text) == 0) return 0
14+
messageField.setText("")
15+
chatHistory.setText(chatHistory.getText() + "<br><b>вы</b> > " + text)
16+
thread(::http, "http://annimon.com/json/bot.php", "POST", {"text": text}, def(answer) {
17+
chatHistory.setText(chatHistory.getText() + "<br><b>бот</b> > " + answer)
18+
})
19+
}
20+
21+
messagePanel = newPanel()
22+
messagePanel.setLayout(boxLayout(messagePanel, BoxLayout.LINE_AXIS))
23+
messagePanel.add(messageField)
24+
messagePanel.add(sendButton)
25+
26+
mainPanel = newPanel(borderLayout(10, 10))
27+
mainPanel.setPreferredSize(400, 250)
28+
mainPanel.add(chatHistory, BorderLayout.CENTER)
29+
mainPanel.add(messagePanel, BorderLayout.SOUTH)
30+
31+
32+
window = newWindow("Чат с самоботом")
33+
window.setMinimumSize(200, 220)
34+
window.setLocationByPlatform()
35+
window.add(mainPanel)
36+
window.pack()
37+
window.setVisible()

0 commit comments

Comments
 (0)