面试题答案
一键面试import tornadofx.*
class MainView : View("My View") {
override val root = vbox {
val textField = textfield()
button("Click me") {
action {
textField.text = "按钮被点击"
}
}
}
}
在上述代码中:
- 首先定义了一个继承自
View
的MainView
类,并指定视图标题为My View
。 - 在
root
布局(这里使用vbox
垂直布局)中,创建了一个textfield
文本框并赋值给textField
变量,同时创建了一个按钮button
。 - 为按钮添加
action
点击事件,在点击事件中设置textField
的文本为按钮被点击
。