mirror of
https://github.com/aNNiMON/Own-Programming-Language-Tutorial.git
synced 2024-09-20 08:44:20 +03:00
36 lines
1.1 KiB
Plaintext
36 lines
1.1 KiB
Plaintext
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()
|