0

I want to open tiles with the left mouseclick and mark them with the right mouseclick. I read and tried a lot but somehow can't get this working.

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());
            }
        }
    }

Could anyonw please help?

Kendel Ventonda
  • 411
  • 3
  • 9
  • 22

1 Answers1

1

Something went wrong with your onMouseClicked handler.

For the correct syntax of lambda expressions, see the Syntax section of the oracle tutorial.

The correct way to do it would be

this.setOnMouseClicked(e -> {
    if (e.getButton() == MouseButton.SECONDARY) {
        open();
    }
});

Furthermore there are some declarations missing in your code snippet:

  • the open method
  • the TILE_SIZE field
fabian
  • 80,457
  • 12
  • 86
  • 114