I get EventHandler from another class, and I want to set this EventHandler and other ActionEvent to the same button. It is possible?
The code is following. The button is: "btnAdd".
public void addActionListener(EventHandler<ActionEvent> eventHandlerSetNotSave){
btnAdd.setOnAction((e)-> {
FileChooser fileChooser = new FileChooser();
fileChooser.setTitle("Open Resource File");
FileChooser.ExtensionFilter extFilter = new FileChooser.ExtensionFilter("pictures file format",
"*.TIF","*.JPG","*.PNG","*.GIF","*.JEPG");
fileChooser.getExtensionFilters().addAll(extFilter);
File file = fileChooser.showOpenDialog(null);
if (file != null &&
url.equals(emptyImageUrl)? true:alertMessageWarning("The viseme will change, and previous viseme will be delete.")) {
setImage("file:"+file.toString());
changeAfterSaved=false;
}
});
btnAdd.setOnAction(eventHandlerSetNotSave);
btnDelete.setOnAction((e)-> {
changeAfterSaved=true;
setImage(emptyImageUrl);
});
}
Call the addEventHandler()
method instead of setOnAction(...)
:
btnAdd.addEventHandler(ActionEvent.ACTION, (e)-> {
FileChooser fileChooser = new FileChooser();
fileChooser.setTitle("Open Resource File");
FileChooser.ExtensionFilter extFilter = new FileChooser.ExtensionFilter("pictures file format",
"*.TIF","*.JPG","*.PNG","*.GIF","*.JEPG");
fileChooser.getExtensionFilters().addAll(extFilter);
File file = fileChooser.showOpenDialog(null);
if (file != null &&
url.equals(emptyImageUrl)? true:alertMessageWarning("The viseme will change, and previous viseme will be delete.")) {
setImage("file:"+file.toString());
changeAfterSaved=false;
}
});
btnAdd.addEventHandler(ActionEvent.ACTION, eventHandlerSetNotSave);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With