Own-Programming-Language-Tu.../examples/forms/samobot_chat.own

36 lines
1.1 KiB
Scala
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

use std, http, forms
chatHistory = newLabel("<html>Чат с самоботом<br>")
messageField = newTextField()
sendButton = newButton("Отправить")
messageField.onAction(::onSend)
sendButton.onClick(::onSend)
def onSend() {
text = messageField.getText()
if (length(text) == 0) return 0
messageField.setText("")
chatHistory.setText(chatHistory.getText() + "<br><b>вы</b> > " + text)
thread(::http, "https://annimon.com/json/bot.php", "POST", {"text": text}, def(answer) {
chatHistory.setText(chatHistory.getText() + "<br><b>бот</b> > " + answer)
})
}
messagePanel = newPanel()
messagePanel.setLayout(boxLayout(messagePanel, BoxLayout.LINE_AXIS))
messagePanel.add(messageField)
messagePanel.add(sendButton)
mainPanel = newPanel(borderLayout(10, 10))
mainPanel.setPreferredSize(400, 250)
mainPanel.add(chatHistory, BorderLayout.CENTER)
mainPanel.add(messagePanel, BorderLayout.SOUTH)
window = newWindow("Чат с самоботом")
window.setMinimumSize(200, 220)
window.setLocationByPlatform()
window.add(mainPanel)
window.pack()
window.setVisible()