JavaFX矩形侦听器

时间:2018-07-14 19:33:28

标签: java javafx

我正在编写一个程序,该程序将具有钢琴形状的矩形。我想在按下一个键时写到控制台,但是当我按下一个键时,什么也没发生。在fxml中,我让每个矩形的onMouseClicked等于#keyPressed,因此它应该激活代码。

@FXML
    public void keyPressed(Event e) {
        String keyPressed = ((Control)e.getSource()).getId();

        System.out.println(keyPressed + " Key");
        playNote(60, 1);
    }

矩形代码:

<Rectangle id="A0" arcHeight="5.0" arcWidth="5.0" fill="WHITE" height="336.0" onMouseClicked="#keyPressed" stroke="BLACK" strokeType="INSIDE" styleClass="whiteKey" width="37.0" />

我无法使用解决方案here。感谢您的帮助。

0 个答案:

没有答案