【发布时间】:2016-07-22 18:04:50
【问题描述】:
我想用鼠标左键打开图块并用鼠标右键标记它们。我阅读并尝试了很多,但不知何故无法使其正常工作。
private class Tile extends StackPane {
private int x, y;
private boolean hasBomb;
private boolean isOpen = false;
private Rectangle border = new Rectangle(TILE_SIZE - 2, TILE_SIZE - 2);
private Text text = new Text();
public Tile(int x, int y, boolean hasBomb) {
this.x = x;
this.y = y;
this.hasBomb = hasBomb;
border.setStroke(Color.BLACK);
border.setFill(Color.GREY);
text.setFont(Font.font(18));
text.setText(hasBomb ? "X" : "");
text.setVisible(false);
getChildren().addAll(border, text);
setTranslateX(x * TILE_SIZE);
setTranslateY(y * TILE_SIZE);
onMouseClicked: function(e:MouseEvent):Void {
if (e.button == MouseButton.SECONDARY) {
setOnMouseClicked(e -> open());
}
}
}
有人可以帮忙吗?
【问题讨论】:
-
定义“不工作”。你在那里的东西看起来像一个语法错误。它肯定不是 Java。
-
抱歉,有几个语法错误。我以此为例:stackoverflow.com/questions/1515547/right-click-in-javafx
-
@KendelVentonda:那是 JavaFX 脚本,不再支持。