Most likely you have the following in your FXML:
<Button fx:id="forgot" onAction="#forgetPasswordClicked" />
This makes your button forgot
call your method forgetPasswordClicked()
. But instead of defining your logic to be executed when your button is clicked, the first time you say: "When this button is clicked, place an action event
on my button which will call setUpWindow()
"
forgot.setOnAction(e -> ForgotPassword.setUpWindow());
Therefore, your first click "sets up" the logic of your button. The second click, actually executes it. To solve this, either immediately use your logic as such:
public void forgetPasswordClicked() {
ForgotPassword.setUpWindow();
}
or don't define the method to be called in your fxml, and move the initialization of your button (setting the action listener) to your initialization as following:
public class ControllerSignIn implements Initializable {
@FXML
private Button forgot;
@FXML
private Button back;
@Override
public void initialize(URL location, ResourceBundle resources) {
forgot.setOnAction(e -> ForgotPassword.setUpWindow());
back.setOnAction(e -> ForgotPassword.closeWindow());
}
}
This is also why your signInClicked()
method works from the first click, because it actually executes the logic instead of setting up the handler first.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…