0
色付きの列を描画するための画像をクリックするScalaインターフェイスを作成します。 Enterキーが押されたかどうかを検出したいと思います。ここに私の暫定的なコードは次のとおりです。Scala GUIが押されたキーに応答しません
def main = {
def top = new MainFrame {
title = "Reactive Swing App"
val label = new Label {
var matRaw, mat = new Mat
mat = Imgcodecs.imread("data/batch/14-ZoneDetection/01-noExtraCol/VISSAGE_115.jp2", Imgcodecs.CV_LOAD_IMAGE_COLOR) // images are stored as 8UC3
Image.printCaracColor("mat", mat)
var buf = toBufferedImage(mat)
icon = new ImageIcon(buf)
listenTo(mouse.clicks) // mouse.clicks is a member of Label, this is why the click position is relative to the label
listenTo(keys)
reactions += {
case MousePressed(_, point, _, _, _) => {
mat.submat(0, mat.rows, point.getX.toInt, point.getX.toInt + 1).setTo(new Scalar(0.0, 255.0, 0.0))
buf = toBufferedImage(mat)
icon = new ImageIcon(buf)
println("Click position, x: " + point.getX + ", y: " + point.getY)
}
}
reactions += {
case KeyPressed(_, Key.Enter, _, _) => {
println("Enter pressed")
}
}
}
contents = label
}
val frame = top
frame.resizable = false
frame.visible = true
}
適切case MousePressed
作品と緑の列が正しく表示された画像に付加されます。ただし、case KeyPressed
は機能しません。これを解決する手助けをしてもらえますか?
イメージを 'JButton'の' ImageIcon'に使用します。 'ActionListener'をボタンに追加します。マウスのクリックとキーの押下の両方に応答する必要があります。 –