【发布时间】:2020-06-17 17:10:26
【问题描述】:
我尝试使用 Kotlin 和 TornadoFX 库中的套接字连接来实现一个聊天应用程序来制作 GUI。 当我尝试启动客户端时出现问题,因为它一直在等待来自服务器的消息,尽管我将更新标签并接收消息的代码放在 runAsync 中。我红色了 TornadoFX 文档并观看了 youtube 视频,但我无法找到解决方案。 我知道问题是程序卡在那个块中,但不知道该怎么做。
class MyFirstView: View("Chat"){
var input: TextField by singleAssign()
var test = SimpleStringProperty()
val client: Client by inject()
init {
client.connect()
val t = thread(true) {
while (true) {
random = client.getMessage()
println(random)
Platform.runLater { test.set(random) }
}
}
}
override val root = vbox {
hbox {
label(test) {
bind(test)
}
}
hbox {
label("Write here some text")
input = textfield()
}
hbox {
button("Send") {
action{
client.writer.println(input.text)
}
}
}
}
}
【问题讨论】: