a simple way like
FXML
create 2 buttons call B1 and B2, and add fx:id for each button)
<?xml version="1.0" encoding="UTF-8"?>
<?import java.lang.*?>
<?import java.util.*?>
<?import javafx.scene.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<AnchorPane id="AnchorPane" prefHeight="200" prefWidth="320" xmlns:fx="http://javafx.com/fxml/1" xmlns="http://javafx.com/javafx/8" fx:controller="ask.FXMLDocumentController">
<children>
<Button fx:id="B1" layoutX="94.0" layoutY="106.0" text="B1" />
<Button fx:id="B2" layoutX="195.0" layoutY="106.0" text="B2" />
</children>
</AnchorPane>
Controller
use setOnAction method to change value
Button name must same as what fx:id set
import java.net.URL;
import java.util.ResourceBundle;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.Button;
public class FXMLDocumentController implements Initializable {
@FXML Button B1;
@FXML Button B2;
int whichIsLastClicked = -1;
public void initialize(URL url, ResourceBundle rb)
{
B1.setOnAction(e->whichIsLastClicked=1);
B2.setOnAction(e->whichIsLastClicked=2);
}
}