She*_*len 5 scala javafx scalafx
我想definde的的OnAction的安信永巴顿在完成scalafx,但我不能让它工作.
package App.Desktop
import javafx.event.EventHandler
import scalafx.event.ActionEvent
import scalafx.scene.control.Button
class Window() {
btn_YES.onAction = (event: ActionEvent) =>
new EventHandler[ActionEvent] {
override def handle(event: ActionEvent) {
/*Do something*/
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
我做到了这一点,但是我收到了一个错误
Error: type mismatch;
found : scalafx.event.ActionEvent => javafx.event.EventHandler[scalafx.event.ActionEvent]
required: javafx.event.EventHandler[javafx.event.ActionEvent]
btn_YES.onAction = (event: ActionEvent) => new EventHandler[ActionEvent]
Run Code Online (Sandbox Code Playgroud)
我也尝试使用javafx.event.ActionEvent而不是scalafx但它也不起作用.
任何线索?
谢谢
我不是 Scala 程序员,但看起来您在这里混合了两种不同的形式:lambda 表达式和显式类。
尝试
package App.Desktop
import javafx.event.EventHandler
import javafx.event.ActionEvent
import scalafx.scene.control.Button
class Window() {
btn_YES.onAction =
new EventHandler[ActionEvent] {
override def handle(event: ActionEvent) {
/*Do something*/
}
}
}
Run Code Online (Sandbox Code Playgroud)
或者
package App.Desktop
import javafx.event.EventHandler
import javafx.event.ActionEvent
import scalafx.scene.control.Button
class Window() {
btn_YES.onAction = (event: ActionEvent) => {
/*Do something*/
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2274 次 |
| 最近记录: |